Skip to content

Conversation

davidgarciaanton
Copy link
Contributor

Prevent Double Free Crash

ViewNode2 was freeing material by it's own, also didMaterialLoader when exiting composition. Given that situation a crash was happening when using a Scene that uses ViewNode2 renderables.

The fix

To fix that the MaterialLoader tracks it's allocated materials, and the ViewNode2 destroy the material through the MaterialLoader instead of deleting the instance directly from the Engine

@ThomasGorisse ThomasGorisse merged commit 65b397b into SceneView:main Apr 19, 2025
1 check passed
@kalmanbencze
Copy link

hey @ThomasGorisse there seems to be a similar crash on the nodes release:

2025-06-02 11:45:35.172 Sceneview                           com.sugarcube.app.example    D  CameraStream destroyed
2025-06-02 11:45:35.182 Filament                            com.sugarcube.app.example    E  PanicLog
                                                                                            in terminateAndDestroy:982
                                                                                            reason: Object <no-rtti> at 0xb4000079ae02b1d0 doesn't exist (double free?)
2025-06-02 11:45:35.182 Filament                            com.sugarcube.app.example    E  
2025-06-02 11:45:35.219 native                              com.sugarcube.app.example    I  I0000 00:00:1748853935.219896   18634 jni_util.cc:91] Exiting thread. Detach thread.
2025-06-02 11:45:35.249 native                              com.sugarcube.app.example    W  W0000 00:00:1748853935.249675   18723 statistics.cc:265] Reset statistics may cause dangling handle issue
2025-06-02 11:45:35.249 native                              com.sugarcube.app.example    I  I0000 00:00:1748853935.249850   18723 session_lite_c_api.cc:39] Deleted ArSession.
--------- beginning of crash
2025-06-02 11:45:35.599 libc                                com.sugarcube.app.example    A  Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 17971 (ube.app.example), pid 17971 (ube.app.example)
2025-06-02 11:45:36.310 DEBUG                               pid-18744                    A  Cmdline: com.sugarcube.app.example
2025-06-02 11:45:36.310 DEBUG                               pid-18744                    A  pid: 17971, tid: 17971, name: ube.app.example  >>> com.sugarcube.app.example <<<
2025-06-02 11:45:36.310 DEBUG                               pid-18744                    A        #07 pc 0000000000378158  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (com.google.ar.core.Anchor.detach+0)
2025-06-02 11:45:36.310 DEBUG                               pid-18744                    A        #12 pc 0000000000436ee4  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (io.github.sceneview.ar.node.AnchorNode.detachAnchor+0)
2025-06-02 11:45:36.310 DEBUG                               pid-18744                    A        #17 pc 0000000000436ea8  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (io.github.sceneview.ar.node.AnchorNode.destroy+0)
2025-06-02 11:45:36.310 DEBUG                               pid-18744                    A        #22 pc 000000000040e884  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (io.github.sceneview.SceneKt$rememberNodes$lambda$31$lambda$30$lambda$29$$inlined$onDispose$1.dispose+0)
2025-06-02 11:45:36.310 DEBUG                               pid-18744                    A        #27 pc 0000000000193338  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (androidx.compose.runtime.DisposableEffectImpl.onForgotten+0)
2025-06-02 11:45:36.310 DEBUG                               pid-18744                    A        #32 pc 0000000000188248  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (androidx.compose.runtime.CompositionImpl$RememberEventDispatcher.dispatchRememberObservers+0)
2025-06-02 11:45:36.310 DEBUG                               pid-18744                    A        #37 pc 000000000018d874  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (androidx.compose.runtime.CompositionImpl.dispose+0)
2025-06-02 11:45:36.310 DEBUG                               pid-18744                    A        #42 pc 00000000002d7550  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (androidx.compose.ui.layout.LayoutNodeSubcompositionsState.disposeCurrentNodes+0)
2025-06-02 11:45:36.310 DEBUG                               pid-18744                    A        #47 pc 00000000002d8218  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (androidx.compose.ui.layout.LayoutNodeSubcompositionsState.onRelease+0)
2025-06-02 11:45:36.310 DEBUG                               pid-18744                    A        #52 pc 0000000000304fd4  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (androidx.compose.ui.node.LayoutNode.onRelease+0)
2025-06-02 11:45:36.310 DEBUG                               pid-18744                    A        #57 pc 0000000000188248  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (androidx.compose.runtime.CompositionImpl$RememberEventDispatcher.dispatchRememberObservers+0)
2025-06-02 11:45:36.310 DEBUG                               pid-18744                    A        #62 pc 000000000018d874  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (androidx.compose.runtime.CompositionImpl.dispose+0)
2025-06-02 11:45:36.310 DEBUG                               pid-18744                    A        #67 pc 000000000035c2dc  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (androidx.compose.ui.platform.WrappedComposition.dispose+0)
2025-06-02 11:45:36.310 DEBUG                               pid-18744                    A        #72 pc 0000000000322d10  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (androidx.compose.ui.platform.AbstractComposeView.disposeComposition+0)
2025-06-02 11:45:36.310 DEBUG                               pid-18744                    A        #77 pc 0000000000355bac  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (androidx.compose.ui.platform.ViewCompositionStrategy$DisposeOnDetachedFromWindowOrReleasedFromPool$installFor$listener$1.onViewDetachedFromWindow+0)
2025-06-02 11:45:36.310 DEBUG                               pid-18744                    A        #98 pc 000000000018e36c  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (androidx.fragment.app.FragmentContainerView.removeView+0)
2025-06-02 11:45:36.310 DEBUG                               pid-18744                    A        #103 pc 00000000001af8d8  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (androidx.fragment.app.SpecialEffectsController$Operation$State.applyState+0)
2025-06-02 11:45:36.311 DEBUG                               pid-18744                    A        #108 pc 00000000001b0f80  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (androidx.fragment.app.SpecialEffectsController.applyContainerChangesToOperation$fragment_release+0)
2025-06-02 11:45:36.311 DEBUG                               pid-18744                    A        #113 pc 00000000001b101c  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (androidx.fragment.app.SpecialEffectsController.commitEffects$fragment_release+0)
2025-06-02 11:45:36.311 DEBUG                               pid-18744                    A        #118 pc 00000000001b17dc  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (androidx.fragment.app.SpecialEffectsController.executePendingOperations+0)
2025-06-02 11:45:36.311 DEBUG                               pid-18744                    A        #123 pc 0000000000199ffc  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (androidx.fragment.app.FragmentManager.executeOpsTogether+0)
2025-06-02 11:45:36.311 DEBUG                               pid-18744                    A        #128 pc 000000000019b7f8  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute+0)
2025-06-02 11:45:36.311 DEBUG                               pid-18744                    A        #133 pc 0000000000195e88  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (androidx.fragment.app.FragmentManager.execPendingActions+0)
2025-06-02 11:45:36.311 DEBUG                               pid-18744                    A        #138 pc 0000000000191f00  /data/app/~~55TctXFyp-TjAmwSSHQM0Q==/com.sugarcube.app.example-x8oWUYGa65rhbILhiTc0yQ==/base.apk (androidx.fragment.app.FragmentManager$5.run+0)
---------------------------- PROCESS ENDED (17971) for package com.sugarcube.app.example ----------------------------
2025-06-02 11:45:55.998 audit                               auditd                       E  type=1400 audit(1748853955.993:923329): avc:  granted  { execute } for  pid=18821 comm="re-initialized>" path="/data/data/com.sugarcube.app.example/code_cache/startup_agents/1b62897e-agent.so" dev="dm-53" ino=956617 scontext=u:r:untrusted_app:s0:c227,c259,c512,c768 tcontext=u:object_r:app_data_file:s0:c227,c259,c512,c768 tclass=file SEPF_SM-S901B_12_0001 audit_filtered
---------------------------- PROCESS STARTED (18821) for package com.sugarcube.app.example ----

Seems that the nodes get double freed as well. I can reproduce this every single time with ARScene and 1 model.

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

Successfully merging this pull request may close these issues.

3 participants