Skip to content

Commit 6631f9d

Browse files
committed
handle null surface holder
1 parent 161137e commit 6631f9d

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

core/src/processing/core/PApplet.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,11 @@ public void onPermissionsGranted() {
785785
// TODO this is only used by A2D, when finishing up a draw. but if the
786786
// surfaceview has changed, then it might belong to an a3d surfaceview. hrm.
787787
public SurfaceHolder getSurfaceHolder() {
788-
return surfaceView.getHolder();
789-
// return surfaceHolder;
788+
if (surfaceView != null) {
789+
return surfaceView.getHolder();
790+
} else {
791+
return null;
792+
}
790793
}
791794

792795

core/src/processing/core/PGraphicsAndroid2D.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import android.graphics.*;
3434
import android.graphics.Bitmap.Config;
3535
import android.graphics.Paint.Style;
36+
import android.view.SurfaceHolder;
3637

3738

3839
/**
@@ -208,17 +209,21 @@ public void endDraw() {
208209
// }
209210

210211
if (primaryGraphics) {
211-
Canvas screen = null;
212-
try {
213-
screen = parent.getSurfaceHolder().lockCanvas(null);
214-
if (screen != null) {
215-
screen.drawBitmap(bitmap, new Matrix(), null);
216-
}
217-
} finally {
218-
if (screen != null) {
219-
parent.getSurfaceHolder().unlockCanvasAndPost(screen);
212+
SurfaceHolder holder = parent.getSurfaceHolder();
213+
if (holder != null) {
214+
Canvas screen = null;
215+
try {
216+
screen = holder.lockCanvas(null);
217+
if (screen != null) {
218+
screen.drawBitmap(bitmap, new Matrix(), null);
219+
}
220+
} finally {
221+
if (screen != null) {
222+
holder.unlockCanvasAndPost(screen);
223+
}
220224
}
221225
}
226+
222227
} else {
223228
// TODO this is probably overkill for most tasks...
224229
loadPixels();

0 commit comments

Comments
 (0)