Skip to content

Commit 099a778

Browse files
update: prevent crash on scene reload
1 parent 3c3d39e commit 099a778

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

android/sharedCode/src/main/java/com/viro/core/Renderer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ public Renderer(ClassLoader appClassLoader, Context context,
9090
}
9191

9292
public void drawFrame() {
93-
nativeDrawFrame(mNativeRef);
93+
if (mNativeRef != 0) {
94+
nativeDrawFrame(mNativeRef);
95+
}
9496
}
9597
public void setVRModeEnabled(boolean enabled) { nativeSetVRModeEnabled(mNativeRef, enabled); }
9698

android/sharedCode/src/main/java/com/viro/core/ViroViewARCore.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ public void onSurfaceChanged(GL10 gl, int width, int height) {
297297
if (view == null || view.mSurfaceView == null) {
298298
return;
299299
}
300+
301+
if (view.mDestroyed || view.mNativeRenderer == null) {
302+
return;
303+
}
304+
300305
view.mNativeRenderer.onSurfaceChanged(view.mSurfaceView.getHolder().getSurface(), width, height);
301306

302307
// Notify ARCore session that the view size changed so that the perspective matrix and
@@ -316,11 +321,25 @@ public void onDrawFrame(GL10 gl) {
316321
if (view == null) {
317322
return;
318323
}
324+
325+
// Check if the view has been destroyed or is being destroyed
326+
if (view.mDestroyed) {
327+
return;
328+
}
319329

320-
for (int i = 0; i < view.mFrameListeners.size(); i++) {
321-
view.mFrameListeners.get(i).onDrawFrame();
330+
if (view.mFrameListeners != null) {
331+
for (int i = 0; i < view.mFrameListeners.size(); i++) {
332+
view.mFrameListeners.get(i).onDrawFrame();
333+
}
334+
}
335+
336+
// Only draw if renderer is valid, initialized, has a scene, and ARCore is installed
337+
if (view.mNativeRenderer != null
338+
&& view.mRendererSurfaceInitialized.get()
339+
&& view.mCurrentScene != null
340+
&& view.mARCoreInstalled.get()) {
341+
view.mNativeRenderer.drawFrame();
322342
}
323-
view.mNativeRenderer.drawFrame();
324343
}
325344
}
326345

0 commit comments

Comments
 (0)