Search Unity

Question Android app crashes if the AR subsystems are deinitialized while a cloud anchor is still resolving

Discussion in 'AR' started by chankeiro, Feb 2, 2023.

  1. chankeiro

    chankeiro

    Joined:
    Oct 25, 2021
    Posts:
    11
    ARFoundation vs: 4.2.7
    Unity vs: 2021.3.11f1
    OS: Android 12

    Hi all,

    When unloading a Unity scene, I call LoaderUtility.Deinitialize() and then LoaderUtility.Initialize() before loading the next scene, because I usually work with objects like CloudAnchors that I don't want to preserve between scenes. It works fine in most cases, but there is one situation that generates a native crash (signal 11 SIGSEGV). It happens while the system is resolving a cloud anchor. If the cloud anchor is still in CloudAnchorState.TaskInProgress and I call LoaderUtility.Deinitialize(), the app crashes on Android with this SIGSEGV error. However, it doesn't crash if I deinitialize after the anchor has reached CloudAnchorState.Success.

    While in TaskInprogress state, in the logcat I can see that there is a thread making calls to what I think is the ARCloud Api backend trying to resolve the anchor. This is the logcat:
    Code (CSharp):
    1. JniHelper: attached thread (Called from line 217).
    2. JniHelper: about to detach thread (Called from line 217).
    3. JniHelper: detached thread (Called from line 217).
    4. W0000 00:00:1675348850.684429   15494 cloud_anchor_watcher.cc:705] No valid responses were returned from the server: NOT_FOUND: No anchor_t_camera transforms were found.
    5. === Source Location Trace: ===
    6. third_party/arcore/ar/persistence/cloud_anchor_watcher.cc:666
    The pattern I found is that, while the app is doing these calls, trying to deinitialize the AR Subsystems crashes it.

    I have tried several strategies to prevent the system from continuing to track the anchor before deinitializing the ar systems, but with no success. There is a detach() method in the ARCore Android SDK that seems to do exactly what I need https://developers.google.com/ar/de...veloper-guide#cancel_or_remove_a_cloud_anchor but I don't see an equivalent in ARFoundation, except by destroying the GameObject that represents the anchor with Destroy(anchor.gameObject), which theoretically also detaches the anchor for the session, https://developers.google.com/ar/re...e/XR/ARCoreExtensions/ARCloudAnchor#ondestroy but it doesn't help to prevent the crash.

    I've gone through a lot of ARFoundation documentation and samples, but I haven't found a solution yet.

    This is the code that crashes:
    Code (CSharp):
    1. // If _arCloudAnchor is in CloudAnchorState.TaskInProgress, the following code generates the SIGSEGV crash
    2.  
    3. if (_arCloudAnchor.gameObject != null)
    4. {
    5.      Destroy(_arCloudAnchor.gameObject);
    6. }
    7.  
    8. SceneManager.LoadScene(0);
    9. LoaderUtility.Deinitialize();
    This is the crash:
    Code (CSharp):
    1.  *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    2. Version '2021.3.11f1 (0a5ca18544bf)', Build type 'Release', Scripting Backend 'il2cpp', CPU 'arm64-v8a'
    3. Build fingerprint: 'POCO/lmi_eea/lmi:12/SKQ1.211006.001/V13.0.5.0.SJKEUXM:user/release-keys'
    4. Revision: '0'
    5. ABI: 'arm64'
    6. Timestamp: 2023-02-02 15:40:51+0100
    7. pid: 14600, tid: 15494, name: Thread-88  >>> com.bercetech.fleepas.debug <<<
    8. uid: 10419
    9. signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x7900000018
    10. x0  b400007d6bb9e5e0  x1  b4000078ddc72cc0  x2  000000000000ca12  x3  00000078ef0ca9f0
    11. x4  00000078ef0ca678  x5  b400007d984a3ddd  x6  6f7073746f68390a  x7  3137653630622f74
    12. x8  0000007900000000  x9  000000791dc340b8  x10 00000000ffffffff  x11 0000007903b00a1c
    13. x12 0199999999999999  x13 0000000000000080  x14 d028af96de096b4e  x15 0000000080000000
    14. x16 0000007eb4d90d60  x17 0000007eb4d80654  x18 00000078e9584000  x19 b400007d8c511888
    15. x20 00000078ef0ca9f0  x21 b400007d6bb9e5e0  x22 b4000078ddc0fe10  x23 b4000078ddc72cc0
    16. x24 000000000000ca12  x25 b4000078ddc0fe28  x26 00000078ef0cb000  x27 b400007971522500
    17. x28 b400007971522518  x29 b400007df2f03f10
    18. sp  00000078ef0ca870  lr  000000791dc34664  pc  000000791dc346a4
    19. backtrace:
    20. #00 pc 0000000001b996a4  /data/app/~~055EZaO9zA7f6K9NPokqQQ==/com.google.ar.core-JxqCQPsaGDQ_jZdLYTGe0Q==/base.apk (BuildId: a3356455c642199cf0332f847b9875f9)
    21. #01 pc 0000000001b9e9fc  /data/app/~~055EZaO9zA7f6K9NPokqQQ==/com.google.ar.core-JxqCQPsaGDQ_jZdLYTGe0Q==/base.apk (BuildId: a3356455c642199cf0332f847b9875f9)
    22. #02 pc 0000000001b72004  /data/app/~~055EZaO9zA7f6K9NPokqQQ==/com.google.ar.core-JxqCQPsaGDQ_jZdLYTGe0Q==/base.apk (BuildId: a3356455c642199cf0332f847b9875f9)
    23. #03 pc 00000000012a58fc  /data/app/~~055EZaO9zA7f6K9NPokqQQ==/com.google.ar.core-JxqCQPsaGDQ_jZdLYTGe0Q==/base.apk (BuildId: a3356455c642199cf0332f847b9875f9)
    24. #04 pc 00000000012a4028  /data/app/~~055EZaO9zA7f6K9NPokqQQ==/com.google.ar.core-JxqCQPsaGDQ_jZdLYTGe0Q==/base.apk (BuildId: a3356455c642199cf0332f847b9875f9)
    25. #05 pc 000000000129fffc  /data/app/~~055EZaO9zA7f6K9NPokqQQ==/com.google.ar.core-JxqCQPsaGDQ_jZdLYTGe0Q==/base.apk (BuildId: a3356455c642199cf0332f847b9875f9)
    26. #06 pc 00000000000efb14  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+264) (BuildId: 94065bf91428f6ae9fb310c478171302)
    27. #07 pc 000000000008c35c  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+68) (BuildId: 94065bf91428f6ae9fb310c478171302)

    Thanks in advance
     
    KyryloKuzyk likes this.
  2. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
  3. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
    Note that deinitializing and reinitializing the XRLoader might also be more heavyhanded than necessary to handle a scene transition? Does ARSession.Reset() not suffice? (I haven't used cloud anchors but at least for all of our AR subsystems that should clear the trackable data.)
     
  4. chankeiro

    chankeiro

    Joined:
    Oct 25, 2021
    Posts:
    11
    Hi andyb. Thanks for your reply. Yes, I also tried ARSession.Reset(), but unfortunately I get the same crash.

    I will then fill the issue with Google. Thanks again.

    EDIT: I just saw that there is an open issue very similar to mine, so I think I'll follow that one. I leave it here just in case someone else is interested.
    https://github.com/google-ar/arcore-unity-extensions/issues/90
     
    Last edited: Feb 2, 2023
    andyb-unity likes this.