Azure / azure-spatial-anchors-samples

Azure Spatial Anchors sample code
Other
293 stars 139 forks source link

Crash when using coarse relocalization happen randomly on iOS #323

Closed tomkrikorian closed 2 years ago

tomkrikorian commented 2 years ago

Description

In our App, we use coarse relocalization running all the time with a watcher. We stop the watcher when we have to :

  1. We stop the watcher :

    _watcher.Stop();

  2. We save an anchor or delete an anchor.
  3. We start the watcher again like this (not resetting the session before launching the watcher makes the app crash too) :

    await _spatialAnchorManager.ResetSessionAsync(); _watcher = _spatialAnchorManager.Session.CreateWatcher(_anchorLocateCriteria);

  4. After a while, the app might crash randomly.

Steps to reproduce the issue

Don't have a steps to repro since it's not part of the sample. Here is the part of the crash log that might help :

Thread 1 name: Thread 1 Crashed: 0 libsystem_kernel.dylib 0x00000001b7e2b964 __pthread_kill + 8 1 libsystem_pthread.dylib 0x00000001f19e4378 pthread_kill + 268 (pthread.c:1610) 2 libsystem_c.dylib 0x000000018bd02f50 abort + 164 (abort.c:118) 3 libsystem_c.dylib 0x000000018bd5996c __assert_rtn + 300 (assert.c:96) 4 AzureSpatialAnchors 0x00000001049cd0e8 0x104198000 + 8605928 5 AzureSpatialAnchors 0x0000000104687b64 0x104198000 + 5176164 6 AzureSpatialAnchors 0x00000001042e9508 0x104198000 + 1381640 7 AzureSpatialAnchors 0x00000001042e99b0 0x104198000 + 1382832 8 AzureSpatialAnchors 0x000000010432f4d4 0x104198000 + 1668308 9 AzureSpatialAnchors 0x00000001041d2760 0x104198000 + 239456 10 libdispatch.dylib 0x0000000180b3b660 _dispatch_client_callout + 20 (object.m:560) 11 libdispatch.dylib 0x0000000180b4cef0 _dispatch_root_queue_drain + 684 (inline_internal.h:2601) 12 libdispatch.dylib 0x0000000180b4d5f8 _dispatch_worker_thread2 + 164 (queue.c:6930) 13 libsystem_pthread.dylib 0x00000001f19de0b8 _pthread_wqthread + 228 (pthread.c:2554) 14 libsystem_pthread.dylib 0x00000001f19dde94 start_wqthread + 8

Expected behavior

Running coarse relocalization without a crash.

Development information (please complete the following information)

AR Device information (please complete the following information):

phamqduc commented 2 years ago

Hi @tomkrikorian, Thank you for letting us know the issues that you experienced around coarse relocalization feature. In order of us to better understand and reproduce the issues, could you please try to applying the above mentioned steps similarly onto the Unity/iOS sample (Coarse Reloc demo) to see if it's working and hence, having another point of reference for debugging your app? For example,

Moreover, could you please elaborate your observations/findings w.r.t the following:

tomkrikorian commented 2 years ago

Little update, someone on my team is going to try your suggestions. We'll get back to you with what we got from our tests.

Morgane-Minsar commented 2 years ago

Hi @phamqduc I am tomkrikorian’s colleague, I am taking the case. I tried your suggestions in your sample by creating a fork from your repository to a new one. You can see the new repository here. I duplicated the scene AzureSpatialAnchorsCoarseRelocDemo to AdvancedAzureSpatialAnchorsCoarseRelocDemo as well as the script AzureSpatialAnchorsCoarseRelocDemoScript for AzureSpatialAnchorsCoarseRelocDemoScriptAdvanced I use in my new scene.

I tried then to build and test on my iPhone 12 pro. See all steps I did:

  1. open the scene AdvancedAzureSpatialAnchorsCoarseRelocDemo
  2. create, configure and start Azure Spatial Anchor session
  3. create location provider and configure sensors
  4. start watcher -> it finds anchors
  5. spawn an object
  6. stop watcher
  7. save anchor, stop Azure Spatial Anchor session
  8. create and start Azure Spatial Anchor session
  9. start watcher -> it finds anchors
  10. stop watcher, stop Azure Spatial Anchor session
  11. reset demo -> it deletes anchors
  12. create, configure and start Azure Spatial Anchor session
  13. create location provider and configure sensors
  14. start watcher -> it doesn’t find anchors
  15. spawn an object
  16. stop watcher
  17. save anchor, stop Azure Spatial Anchor session
  18. create and start Azure Spatial Anchor session
  19. start watcher -> it finally finds anchors

I create a videoshot for you to understand better all steps and the issue. The video is too big for GitHub, let me know if you want it and how I can send it to you. I don’t have any crash, except once but I didn’t know what I was doing. However, you can see that the step 14 is an issue. I have to add an anchor to be able to discover other anchor as I have done steps 15 to 19.

To answer your questions

Does the app only crash during query mode with coarse relocalization?

We only use coarse relocalization, so I don’t know.

If you happen to work on Unity/Android as well, do you see a similar crash? (we try to understand if the issue is cross platforms)

We only work on Unity/iOS and so, our code would not work good enough on Unity/Android to test if there are similar crashes on this platform too.

If you work on iOS app (non-Unity version), do you see a similar crash?

We don’t have enough time to work on iOS app without Unity to test theses crashes. We are focusing the platform iOS with Unity as a development tool.

We really appreciate your reactivity on our issue. Let me know if I can do something else.

msftradford commented 2 years ago

Hi @Morgane-Minsar, thanks so much for the detailed description and source code! It sounds like you are no longer hitting the original reported crash, is that correct? As far as making sure that your watcher returns anchors in step 14, I think that all you need to do is add a call to await CloudManager.ResetSessionAsync(); after you've stopped the previous session in step 10. In your script, that change should look like this:

case AppState.DemoStepStopSessionForQuery:
    CloudManager.StopSession();
    await CloudManager.ResetSessionAsync();
    currentWatcher = null;
    locationProvider = null;
    currentAppState = AppState.DemoStepComplete;
    break;

Let us know if that works. Thanks!

Morgane-Minsar commented 2 years ago

Hi @msftradford, I can confirm that I don't have the original reported crash and also, the reset session solves the issue step 14. Thank you !