BabylonNative - Is it possible to restart an Android activity?

I’ve opened another issue for the cube disappearing

I can repro with just a breakpoint and waiting a little. No need switching to different activities.

Took me a while to figure out what was happening. As usual, it’s pretty stupid.

Running experience.js happens each time the activity view is ready. The second time, it re-creates everything and breaks XR. Simple fix is to not load this script until the engine is disposed or re-initialized. This must be done on the user side/activity side.

1 Like

Partial fix is merged into master.

@Eric_Beets Do you have a list of devices that still crash with the fix? I’ll try to find at least one to repro.

Hi! I’ve tested the current master and it still crashes on my Samsung Galaxy S9.
The logs do look different then before:

W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@2ebb46e
D/PhoneWindow: forceLight changed to true [] from com.android.internal.policy.PhoneWindow.updateForceLightNavigationBar:4268 com.android.internal.policy.DecorView.updateColorViews:1513 com.android.internal.policy.PhoneWindow.dispatchWindowAttributesChanged:3246 android.view.Window.setFlags:1148 com.android.internal.policy.PhoneWindow.generateLayout:2474 
I/MultiWindowDecorSupport: updateCaptionType >> DecorView@a69870f[], isFloating: false, isApplication: true, hasWindowDecorCaption: false, hasWindowControllerCallback: true
D/MultiWindowDecorSupport: setCaptionType = 0, DecorView = DecorView@a69870f[]
I/native: I1004 09:54:33.900764   21882 session.cc:1189] Entering Session::Resume.
I/BabylonNative: BJS - [09:54:33]: FPS: 30
I/native: I1004 09:54:33.908811   21882 estimator_impl.cc:712] Resetting motion tracking from user request.
I/native: I1004 09:54:33.909457   21882 session.cc:3320] Update Frame Delay to 0 frames.
    I1004 09:54:33.909556   21882 android_sensors.cc:185] Starting thread.
I/native: I1004 09:54:33.910159   21882 logger.h:28] DataSourceMetrics: kStartImageSubSystem: 444.538us
    I1004 09:54:33.910211   21882 session.cc:1377] Session::ResumeWithAnalytics returning OK.
E/ACameraMetadata: filterDurations: malformed duration key 851980! count 0, type 3
    filterDurations: malformed duration key 1638402! count 0, type 3
E/ACameraMetadata: filterDurations: malformed duration key 1638403! count 0, type 3
    filterDurations: malformed duration key 1835009! count 0, type 3
    filterDurations: malformed duration key 1835010! count 0, type 3
    filterDurations: malformed duration key 1638407! count 0, type 3
    filterDurations: malformed duration key 1638408! count 0, type 122
I/CameraManagerGlobal: Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_OPEN for client com.android.babylonnative.playground API Level 2
I/native: I1004 09:54:33.927596   22835 android_sensors.cc:45] Gyro min delay 2ms requesting 5ms
I/native: I1004 09:54:33.931886   22835 android_sensors.cc:45] Accel min delay 2ms requesting 5ms
I/native: I1004 09:54:33.944496   22400 logger.h:28] CameraMetrics: OpenCamera: 34.420462ms
D/ViewRootImpl@522a97a[PlaygroundActivity]: setView = com.android.internal.policy.DecorView@a69870f TM=true MM=false
D/SurfaceView: onWindowVisibilityChanged(0) true android.view.SurfaceView{dc1852b V.E...... ......I. 0,0-0,0} of ViewRootImpl@522a97a[PlaygroundActivity]
    onWindowVisibilityChanged(0) false android.view.SurfaceView{c3afd88 I.E...... ......I. 0,0-0,0} of ViewRootImpl@522a97a[PlaygroundActivity]
D/ViewRootImpl@522a97a[PlaygroundActivity]: Relayout returned: old=(0,0,1440,2960) new=(0,0,1440,2960) req=(1440,2960)0 dur=12 res=0x7 s={true 525164965888} ch=true
D/OpenGLRenderer: createReliableSurface : 0x7ac5e1b800(0x7a46457000)
I/mali_winsys: new_window_surface() [1440x2960] return: 0x3000
D/SurfaceView: surfaceCreated 1 #8 android.view.SurfaceView{dc1852b V.E...... ......ID 0,0-1440,2768}
D/SurfaceView: surfaceChanged (1440,2768) 1 #8 android.view.SurfaceView{dc1852b V.E...... ......ID 0,0-1440,2768}
D/SurfaceView: surfaceCreated 1 #3 android.view.SurfaceView{c3afd88 V.E...... ......ID 0,0-1440,2768}
D/SurfaceView: surfaceChanged (1440,2768) 1 #3 android.view.SurfaceView{c3afd88 V.E...... ......ID 0,0-1440,2768}
E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7a44510580
D/: PathToBabylonNative/Dependencies/bgfx.cmake/bgfx/src/renderer_gl.cpp (1186): BGFX src API, type Error, id 1, severity High, 'Error:glDrawArrays::failed to allocate CPU memory'
E/libEGL: eglMakeCurrentImpl:1321 error 300b (EGL_BAD_NATIVE_WINDOW)
D/: PathToBabylonNative/Dependencies/bgfx.cmake/bgfx/src/bgfx.cpp (1691): BGFX Reset back-buffer swap chain:
D/: PathToBabylonNative/Dependencies/bgfx.cmake/bgfx/src/bgfx.cpp (1700): BGFX 	1440x2768, format: RGBA8, numBackBuffers: 2, maxFrameLatency: 0
D/: PathToBabylonNative/Dependencies/bgfx.cmake/bgfx/src/bgfx.cpp (1701): BGFX 	[ ] MSAAx1
    PathToBabylonNative/Dependencies/bgfx.cmake/bgfx/src/bgfx.cpp (1702): BGFX 	[ ] Fullscreen
    PathToBabylonNative/Dependencies/bgfx.cmake/bgfx/src/bgfx.cpp (1703): BGFX 	[ ] V-sync
    PathToBabylonNative/Dependencies/bgfx.cmake/bgfx/src/bgfx.cpp (1704): BGFX 	[x] Max Anisotropy
    PathToBabylonNative/Dependencies/bgfx.cmake/bgfx/src/bgfx.cpp (1705): BGFX 	[ ] Capture
    PathToBabylonNative/Dependencies/bgfx.cmake/bgfx/src/bgfx.cpp (1706): BGFX 	[ ] Flush After Render
    PathToBabylonNative/Dependencies/bgfx.cmake/bgfx/src/bgfx.cpp (1707): BGFX 	[ ] Flip After Render
    PathToBabylonNative/Dependencies/bgfx.cmake/bgfx/src/bgfx.cpp (1708): BGFX 	[ ] sRGB Back Buffer
    PathToBabylonNative/Dependencies/bgfx.cmake/bgfx/src/bgfx.cpp (1709): BGFX 	[ ] HDR10
    PathToBabylonNative/Dependencies/bgfx.cmake/bgfx/src/bgfx.cpp (1710): BGFX 	[ ] Hi-DPI
    PathToBabylonNative/Dependencies/bgfx.cmake/bgfx/src/bgfx.cpp (1711): BGFX 	[ ] Depth Clamp
    PathToBabylonNative/Dependencies/bgfx.cmake/bgfx/src/bgfx.cpp (1712): BGFX 	[ ] Suspend
I/mali_winsys: new_window_surface() [1440x2768] return: 0x3000
I/mali_egl: eglDestroySurface() in
    eglDestroySurface() out
W/libEGL: EGLNativeWindowType 0x7b59180010 disconnect failed
W/mali_winsys: native_window_api_disconnect failed: -19
I/mali_winsys: delete_surface() [1440x2768] return
I/native: I1004 09:54:34.003850   21882 session.cc:3320] Update Frame Delay to 0 frames.
I/BabylonNative: BJS - [09:54:34]: Babylon Native (v5.0.0-alpha.44) launched
I/BabylonNative: BJS - [09:54:34]: Loaded
E/libEGL: eglMakeCurrentImpl:1321 error 300d (EGL_BAD_SURFACE)
W/System: A resource failed to call end. 
I/native: I1004 09:54:34.233309   22400 logger.h:28] CameraMetrics: CreateCaptureSession: 287.631615ms
    I1004 09:54:34.233465   22400 capture_request_utils.cc:207] Flash: ConfigureRequestFlashMode - OFF
I/native: I1004 09:54:34.235655   22394 cameras.cc:1387] Camera 0 changed state CLOSED->OPEN; Camera device opened successfully. i=5
I/native: I1004 09:54:34.235634   22400 logger.h:28] DataSourceMetrics: kFirstGlCallback: 325.917269ms
I/native: I1004 09:54:34.235771   22394 cameras.cc:1387] Camera 0 changed state OPEN->CAPTURING; Started capture session. i=6
D/: PathToBabylonNative/Dependencies/bgfx.cmake/bgfx/src/renderer_gl.cpp (3131): BGFX CHECK glBindFramebuffer(0x8D40, m_backBufferFbo); GL error 0x505: GL_OUT_OF_MEMORY
A/libc: Fatal signal 5 (SIGTRAP), code 1 (TRAP_BRKPT), fault addr 0x7a5ebbc84c in tid 21882 (tive.playground), pid 21882 (tive.playground)
I/CameraManagerGlobal: Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_ACTIVE for client com.android.babylonnative.playground API Level 2
I/native: I1004 09:54:34.691880   22439 timebase_helpers.cc:170] Timebase offset intialized to 0
I/native: I1004 09:54:34.694366   22838 logger.h:28] CameraMetrics: FirstCaptureComplete: 460.851692ms
I/native: I1004 09:54:34.694667   22439 logger.h:28] DataSourceMetrics: kFirstImageCallback: 784.949153ms
I/native: I1004 09:54:34.705134   22836 performance_monitor.cc:115] Event: FeatureExtraction is taking too long, it took 617.806ms
W/native: W1004 09:54:34.707494   22411 vio_initializer.cc:463] Dropped initialization window due to skip in data.
E/native: E1004 09:54:34.707700   22408 epipolar_self_consistency_metrics.cc:164] Failed to create pose node for current timestamp 187499978694
I/native: I1004 09:54:34.708429   22420 data_manager.cc:158] Mapping backend detected fault.
    I1004 09:54:34.708544   22420 data_manager.cc:160] Saving current map to map buffer.
    I1004 09:54:34.708570   22420 data_manager.cc:166] Generated map # 0, ID 6c5d0317-0029-257a-978e-542178314ed4, non-marginalized keyframes 7, landmarks 0
E/native: E1004 09:54:34.806603   22422 motion_tracking_context.cc:1433] Unable to find measurements corresponding to VIO status at timestamp 187599924464.
I/BabylonNative: BJS - [09:54:34]: FPS: 60
I/native: I1004 09:54:35.113407   22411 bundle_adjustment_initializer.cc:263] Intrinsic vector size of the camera 0 is 7
I/native: I1004 09:54:35.141534   22411 bundle_adjustment_initialization.h:136] Number of measurements used in BA initialization for temporal landmarks: 300
    I1004 09:54:35.141628   22411 bundle_adjustment_initialization.h:138] Number of good measurements (i.e., reprojection errors <= 3 pixels) in BA initialization for temporal landmarks: 298
I/BabylonNative: BJS - [09:54:35]: FPS: 60

I just tested on an S9 (specifically SM-G960F/DS) and it doesn’t repro for me, unfortunately :frowning:

@Cedric just to confirm, the fix is merged into master, right? I have tested your test/Android_lifecycle_activities branch, but not master

2 Likes

Ah that’s good to know, if it’s just this one device I have than it must be something else on there. Thank you for checking!

If you have any other devices where the issue repros, let us know and we’d be more than happy to test on those as well. Otherwise, I’m not sure there’s much we can do to help from our end. Is this a blocking issue for you?

2 Likes

Hi! It’s blocking for me since I’d like to know my app works well, but if this is a problem with my phone or somewhere else in my project than that’s on me :smiley:
If I manage to find out what causes it I’ll leave another reply here.
Thanks for looking into it so thoroughly, and great job with this project, it’s a lot of fun to work with!

2 Likes