-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
App crashes after ARSession.Reset() #90
Comments
Hi, I am experiencing the same crash. In my case it only fails if I call ARSession.Reset() or LoaderUtility.Deinitialize() and the cloud anchor is still in CloudAnchorState.TaskInProgress. 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:
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:
The crash looks like this:
ARFoundation vs: 4.2.7 |
Thanks for fixing this. Do you know in which release this fix will be included? |
After updating to vs 1.38 and switching all the CloudAnchor functions to the Promise paradigm as suggested in release 1.37, the problem is solved. |
I tried it with ARCore Extensions 1.43.0.
@devbridie |
WE HAVE FIXED THIS ISSUE ON A UNITY FORM ! check it out. (https://discussions.unity.com/t/ar-foundation-stopped-working-all-of-a-sudden-on-android/936111/23) here's a copy and paste of the comment . im spreading this to see people flourish it took us 2 weeks bashing my head against the wall lol . So question ?:raising_hand_man:t5: And from what you’d said it looks like if we take out the ARSession.Reset then do it after it initializes then we should be ok and the app should stop crashing . So basically I can either do that function separately outside that script or call for that function last after everything is initiated. I’m currently looking to test this theory and see if that works . Any suggestions will be appreciated! We have had this issue for some time now and went back to iOS development now that we are done with it we was hoping we gave some time for them to fix it . Now it’s time to take matters in our own hands if possible. EDIT : SAME DAY After testing this out and debugging the changes and updates in code and with a little help from chat gpt . I realized in the older version of my app (unity 2019) I am using addressables for my tracked images and we had to call for the ARsession to rest in iOS to make sure users always had the most updated tracked images . IOS Can handle this while the AR session is being created but Android can not . Apparently if we call this when the android system is building the Ar.Session it will crash . So between me a chat gpt we came up with a solution too either make the reset for IOS only or make a delay for is if it’s android. here is the summary I hope this helps . We have been working on this for a week and a half now ! !!! NOTE !!! if you have made a script you have added the ARSession.Reset then you must edit it with the same constraints as my script making it have a delay or not do it for android at all Issue Summary The original issue involved crashes occurring on Android devices when attempting to reset the AR session during initialization. This reset was part of a script designed to dynamically update an XR tracked image library from Unity Cloud, a necessity for iOS devices to ensure they always had the most up-to-date XR library. However, on Android, this reset would cause crashes if called while the AR session was still initializing. On iOS, the reset operation worked without issues, but Android’s initialization process couldn’t handle it, leading to instability. Original Script The original script attempted to reset the AR session immediately after starting, which worked well on iOS but caused issues on Android. csharp Copy code using UnityEngine; public class ARSessionRest : MonoBehaviour
} iOS: The reset operation was successful, ensuring that the most recent XR library was loaded without any issues. To resolve this issue and maintain functionality across both platforms, two different solutions were implemented: Platform-Specific Delayed Reset Script: This solution applies a delay before resetting the AR session on Android devices, ensuring the reset only occurs after the AR session is fully initialized. On iOS, the reset happens immediately as before.
This script ensures the reset operation is delayed on Android until the AR session is fully initialized, while iOS performs the reset immediately. csharp Copy code using System.Collections; public class ARSessionRest : MonoBehaviour
#if UNITY_IOS
} iOS: The reset is performed immediately as iOS handles this operation well without causing crashes. This script performs the reset operation only on iOS and skips it entirely on Android. csharp Copy code using UnityEngine; public class ARSessionRest : MonoBehaviour
#if UNITY_IOS iOS: The reset is performed as needed to dynamically update the XR library. With these two updated scripts, you can choose the approach that best fits your needs: Platform-Specific Delayed Reset Script: Ensures the reset is handled carefully on Android by delaying it until the session is fully initialized, while maintaining immediate resets on iOS. Check us out at GameWorlds.online for our future projects ! |
@GameWorldsDEV Because...the proposed solution is:
Platform-Specific Delayed Reset ScriptThe steps to reproduce this issue is to wait 6 minutes or more. Platform-Specific Reset ScriptIf I don't call Reset, the plane I detected remains. Thank you for providing such good information. |
@TakafumiYuasaHL , If you have not already done so before resetting the session, it may help to cancel any pending cloud anchor promises:
I hope it helps. |
@chankeiro I tried cancel promises. Add method to PersistentCloudAnchorsController.cs that calls ARSession.Reset().
This method call in ARViewManager.OnDisable().
Call reset after canceling promises. I'll try different things, thanks!! |
Ok, a workaround while you don't find the cause of the problem might be to disable all your AR managers, destroy trackables, meshes, etc. everything related to your AR session instead of resetting it. Something like that:
If you need the AR capabilities, you can turn them back on:
|
This problem does not occur without Cloud Anchor Mode Enabled.
Adding Session.Reset() to PersistentCloudAnchorsController.cs in ARCore Extensions Samples.
Log when problem occurs.
This issue is occurring in the following environments.
Hardware I'm using for testing:
The text was updated successfully, but these errors were encountered: