Search Issue Tracker
Fixed
Fixed in 5.1.6, 6.0.2
Votes
5
Found in [Package]
5.1.3
6.0.1
Issue ID
ARFB-461
Regression
Yes
[XR][Android] Player crashes when ARSession.Reset() is called after ARSession is instantiated on the device
Reproduction steps:
1. Open the attached project “ReproProject”
2. Ensure that “Google Play Services for AR” app is installed on the device
3. Build And Run
4. Observe the Player
Expected result: The player does not crash
Actual result: Player crashes immediately after launch
Reproducible with: 5.0.6, 5.0.7, 5.1.3 (2021.3.37f1, 2022.3.25f1, 2023.2.19f1), 6.0.0-pre.5, 6.0.1 (6000.0.0b15)
Not reproducible with: 4.2.10, 5.0.5 (2021.3.37f1), 5.0.5 (2022.3.25f1)
Reproducible with these devices:
VLNQA00518 - Google Pixel 4 (Pixel 4), CPU: Snapdragon 855 SM8150, GPU: Adreno 640, OS: 13
VLNQA00414 - Galaxy Note10+ 5G (SM-N976V), CPU: Snapdragon 855 SM8150, GPU: Adreno 640, OS: 9
VLNQA00591 - Samsung Galaxy S23 (SM-S911B), CPU: Snapdragon 8 Gen 2 (SM8550), GPU: Adreno 740, OS: 14
VLNQA00278 - Xiaomi Redmi Note 7 (Redmi Note 7), CPU: Snapdragon 660, GPU: Adreno 512, OS: 9.0.0
VLNQA00139 - Vivo Xplay6 (vivo Xplay6), CPU: Snapdragon 820 MSM8996, GPU: Adreno 530, OS: 7.1.1
VLNQA00132 - Xiaomi Mi 5s (MI 5s), CPU: Snapdragon 820 MSM8996, GPU: Adreno 530, OS: 6.0.1
Samsung Galaxy S22 Ultra (user’s)
Reproduced on: Windows 11 23H2 (22631.3007), Windows 11 (10.0.22631) 64bit (user’s)
Not reproduced on: No other environment tested
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Color mismatch in UI Builders Library panel when the Editors theme is set to Light Mode
- [Android ] "AndroidJNI.ToBooleanArray" returns a random non-zero value instead of "IntPtr.Zero" when the method argument is null
- Non-HDR color picker opens when selecting material color with HDR enabled
- Crash on EditorApplication:Internal_CallUpdateFunctions when pushing property block by index to SpriteShapeRenderer
- Depth Texture Mode "After Opaques" breaks when "Full Screen Pass Renderer Feature" is added
GameWorldsDev
Aug 14, 2024 12:34
the unity docs and google docs where it shows how to reset a d session needs to include this to make sure people don't break their android or iOS apps please .
GameWorldsDev
Aug 14, 2024 12:33
So question ?:
Where you able to find this in the XR Orgin script or AR Session script ?
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;
using UnityEngine.XR.ARFoundation;
public class ARSessionRest : MonoBehaviour
{
[SerializeField]
private ARSession arSession;
void Start()
{
arSession.Reset();
}
}
Issue with Original Script:
iOS: The reset operation was successful, ensuring that the most recent XR library was loaded without any issues.
Android: The script caused crashes because it attempted to reset the AR session while it was still initializing.
Updated Solution Options
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.
Platform-Specific Reset Script: This solution makes the reset platform-specific, where the reset only happens on iOS and is completely skipped on Android. This ensures stability on Android while retaining the necessary functionality on iOS.
1. Platform-Specific Delayed Reset Script
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;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
public class ARSessionRest : MonoBehaviour
{
[SerializeField]
private ARSession arSession;
void Start()
{
#if UNITY_IOS
// Directly reset for iOS as it handles this well
arSession.Reset();
#elif UNITY_ANDROID
// Delay the reset until the session is fully initialized on Android
StartCoroutine(WaitForSessionAndReset());
#endif
}
private IEnumerator WaitForSessionAndReset()
{
// Wait until the AR session is fully initialized
while (ARSession.state != ARSessionState.SessionTracking)
{
yield return null;
}
// Once the session is tracking, reset the AR session
arSession.Reset();
}
}
Explanation:
iOS: The reset is performed immediately as iOS handles this operation well without causing crashes.
Android: The reset is delayed until the AR session is fully initialized, preventing the crashes that occurred due to the reset being called too early.
2. Platform-Specific Reset Script
This script performs the reset operation only on iOS and skips it entirely on Android.
csharp
Copy code
using UnityEngine;
using UnityEngine.XR.ARFoundation;
public class ARSessionRest : MonoBehaviour
{
[SerializeField]
private ARSession arSession;
void Start()
{
#if UNITY_IOS
// Perform the reset only for iOS
arSession.Reset();
#elif UNITY_ANDROID
// Skip the reset entirely for Android
// The AR session will continue without resetting
#endif
}
}
Explanation:
iOS: The reset is performed as needed to dynamically update the XR library.
Android: The reset is skipped to prevent crashes, ensuring stability on this platform while still running the AR session.
Outcome
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.
Platform-Specific Reset Script: Skips the reset on Android entirely, avoiding potential issues while still performing the necessary reset on iOS.
Both solutions maintain the functionality required for iOS devices while ensuring that Android devices no longer crash during the AR session initialization. I hoped we helped out !
Check us out at GameWorlds.online for our future projects !