Merge pull request #4505 from JakubValtar/loadimage-npe

Prevent NPE in loadImage() when called before setup()
This commit is contained in:
Ben Fry
2016-06-02 16:38:40 -04:00
+4 -2
View File
@@ -5246,7 +5246,7 @@ public class PApplet implements PConstants {
// await... has to run on the main thread, because P2D and P3D call GL functions
// If this runs on background, requestImage() already called await... on the main thread
if (!Thread.currentThread().getName().startsWith(ASYNC_IMAGE_LOADER_THREAD_PREFIX)) {
if (g != null && !Thread.currentThread().getName().startsWith(ASYNC_IMAGE_LOADER_THREAD_PREFIX)) {
g.awaitAsyncSaveCompletion(filename);
}
@@ -5403,7 +5403,9 @@ public class PApplet implements PConstants {
public PImage requestImage(String filename, String extension) {
// Make sure saving to this file completes before trying to load it
// Has to be called on main thread, because P2D and P3D need GL functions
g.awaitAsyncSaveCompletion(filename);
if (g != null) {
g.awaitAsyncSaveCompletion(filename);
}
PImage vessel = createImage(0, 0, ARGB);
AsyncImageLoader ail =
new AsyncImageLoader(filename, extension, vessel);