Skip to content

Making a new PGraphics and displaying causes NullPointer #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
processing-bugs opened this issue Jul 18, 2014 · 5 comments
Closed

Making a new PGraphics and displaying causes NullPointer #53

processing-bugs opened this issue Jul 18, 2014 · 5 comments
Assignees

Comments

@processing-bugs
Copy link

Issue by GKFX
Saturday May 31, 2014 at 12:19 GMT
Originally opened as processing/processing-android-archive#68


The simplest form of this is:

PGraphics pg = createGraphics(100, 100);
pg.background(100); //optional
image(pg, 0, 0);

To rectify it, you need to type:

PGraphics pg = createGraphics(100, 100);
pg.background(#ff0000); //optional
pg.loadPixels();
image(pg, 0, 0);
@processing-bugs
Copy link
Author

Comment by GKFX
Saturday May 31, 2014 at 12:22 GMT


Oddly, the second example didn't look right when background was 0;

@Techy4198
Copy link

Techy4198 commented Dec 11, 2016

Why did this get left in the dust? The issue is most certainly still present. Additionally the loadPixels workaround now seems to produce the same error itself.

@codeanticode
Copy link
Contributor

Note that, in order to be able to use a PGraphics correctly, you need to call beginDraw()/enDraw(), as detailed in the tutorials and reference.

I'm able to run the following code without any errors:

PGraphics pg = createGraphics(100, 100);
pg.beginDraw();
pg.background(100);
pg.endDraw();
image(pg, 0, 0);

Please indicate in what specific situations you see the NPE error (also adding what version of the Android mode are you using, and device).

@Techy4198
Copy link

Looking back, I think my issue was actually more centered around trying to render a global PGraphics before it's been drawn to at all. I think I solved it by just drawing a background right after creating it. I guess I can see the reasoning behind an uninitialized canvas being partly treated as null.

@codeanticode
Copy link
Contributor

That's right, before calling beginDraw()/endDraw() at least once, then the PGraphics is not properly initialized for rendering. I think this clarifies the issue, so it can be closed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants