Navigation Menu

Skip to content
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

Persistent crashes on iOS when unloading scene #95

Closed
nilsk123 opened this issue Feb 4, 2019 · 36 comments
Closed

Persistent crashes on iOS when unloading scene #95

nilsk123 opened this issue Feb 4, 2019 · 36 comments
Labels
bug A bug in an ARFoundation-related package fixed Fixed in newer release

Comments

@nilsk123
Copy link

nilsk123 commented Feb 4, 2019

I'm seeing persistent crashes when unloading an AR foundation scene on iOS, even using all the latest software.

When I unload a scene, sometimes it works the first couple of times and then crashes, other times it will crash on first try.

Error in XCode is UnityGfxDeviceWorker (31): EXC_BAD_ACCESS (code=1, address=0xdc56d9600)

Crash log: https://pastebin.com/DUGSPDyS

Software fingerprint:

Unity 2018.3.4f1
iOS 12.1.2
iPhone SE

AR Foundation 1.0.0-preview.22
ARCore XR Plugin 1.0.0-preview.24
ARKit XR Plugin 1.0.0-preview.23

@henriqueranj
Copy link

Hi @nilsk123 , could you provide the symbolicated crash log instead?

See here how to do it: https://developer.apple.cosm/library/archive/technotes/tn2151/_index.html

The easiest way is to get it from XCode via the Devices & Simulators list.

  1. In Xcode > Window > Devices & Simulators , select a connected iPhone/iPad/etc top left.
  2. View Device Logs
  3. All Logs

More: https://stackoverflow.com/a/25927122

@nilsk123
Copy link
Author

nilsk123 commented Feb 5, 2019

Hi @nilsk123 , could you provide the symbolicated crash log instead?

See here how to do it: https://developer.apple.cosm/library/archive/technotes/tn2151/_index.html

The easiest way is to get it from XCode via the Devices & Simulators list.

  1. In Xcode > Window > Devices & Simulators , select a connected iPhone/iPad/etc top left.
  2. View Device Logs
  3. All Logs

More: https://stackoverflow.com/a/25927122

Here it is:

https://pastebin.com/6ZxiP4G1

@ztkevinsy
Copy link

Getting a similar issue with crashing when unloading an AR scene.

https://pastebin.com/LHyrxVs3

@Tostifrosti
Copy link

Same here

@7891liang
Copy link

Unity 2018.3.6
same issue

@Inspyro
Copy link

Inspyro commented May 22, 2019

Can we expect this issue to be fixed? Is there any workaround atm? -> Scenes with ar foundation / Arkit loaded crash when unloaded with the SceneManager.

@dorkbot
Copy link

dorkbot commented May 22, 2019

I had problems with a ARKit image tracking scene crashing in my app. I rebuilt the scene using ARFoundation image tracking and I have no more crashes.

@Inspyro
Copy link

Inspyro commented May 22, 2019

@dorkbot For us it also happens with ARFoundation (but not on every unload)

@nilsk123
Copy link
Author

this hasn't been fixed in the latest versions as far as I can tell (haven't tried the 2.* versions as I don't want to update to unity beta's)

We work around it by just never unloading the AR scene, we disable the gameobjects and keep everything in memory when AR isn't used.

@tdmowrer
Copy link
Contributor

haven't tried the 2.* versions as I don't want to update to unity beta's

ARFoundation 2.1 is compatible with Unity 2019.1 (released) and 2019.2 (beta)
ARFoundation 1.5 is the exact same package compatible with 2018.3/4

We were not able to reproduce the issue in 1.5/2.1. Are you able to update to 1.5?

@nilsk123
Copy link
Author

haven't tried the 2.* versions as I don't want to update to unity beta's

ARFoundation 2.1 is compatible with Unity 2019.1 (released) and 2019.2 (beta)
ARFoundation 1.5 is the exact same package compatible with 2018.3/4

We were not able to reproduce the issue in 1.5/2.1. Are you able to update to 1.5?

It is compatible? Then I have probably misunderstood the docs on this. I will try using the very latest of all plugins (arfoundation, arkit, arcore) and report back here

@nilsk123
Copy link
Author

haven't tried the 2.* versions as I don't want to update to unity beta's

ARFoundation 2.1 is compatible with Unity 2019.1 (released) and 2019.2 (beta)
ARFoundation 1.5 is the exact same package compatible with 2018.3/4

We were not able to reproduce the issue in 1.5/2.1. Are you able to update to 1.5?

Docs say:

Requirements

This version of AR Foundation is compatible with the following versions of the Unity Editor:

2019.2a8 and later

@tdmowrer
Copy link
Contributor

That's an error in the docs (fixing soon).

ARFoundation 2.1 is compatible with Unity 2019.1 (released) and 2019.2 (beta)
ARFoundation 1.5 is the exact same package compatible with 2018.3/4

Is correct.

@kaij
Copy link

kaij commented Aug 23, 2019

I have a well reproducible crash (UnityGfxDeviceWorker / EXC_BAD_ACCESS) using Unity 2019.2.0f1 and ARFoundation 2.1.1 on iOS 12.3. It happens when you do this (around 50% of time):

arSession.enabled = false; 
arCamera.gameObject.SetActive(false);  // <-- comment this out to prevent crash

If you are not deactivating the arCamera, things seem to work fine. I suspect the pointer to the AR texture is freed by the camera deactivation but ar foundation still is writing / tries to write into it. This would be a thread synchronization problem inside the arkit/arfoundation interface.

I have not yet tried disabling the camera in the next frame...

@nilsk123
Copy link
Author

We have temporarily worked around this by disabling multithreaded rendering. Same scenario as above, reset arsession and disable camera gameobject

@NumaNumaNuma
Copy link

I'm having this issue too, 2019.2.0f1 and ARFoundation 3.0.0 preview 2

@nilsk123
Copy link
Author

We still see this problem sporadicaly too, even without multithreaded rendering. Never in test environments ofcourse, only in production =P

My gut feeling is that it has something to do with the fact we use ScreenCapture.CaptureScreenshotAsTexture() around the same time we reset an AR session, but i'm not entirely sure

@NumaNumaNuma
Copy link

NumaNumaNuma commented Sep 25, 2019

for me it's about 90% of the time when ending an AR session.
@tdmowrer Is this being looked at? Or fixed in a newer version of Unity? :)
If you're unable to reproduce it then do you have any ideas what we might be doing wrong?
Thanks!

@NumaNumaNuma
Copy link

NumaNumaNuma commented Sep 26, 2019

I'm getting the same thing when disabling the ARHumanBodyManager, I'm creating a new issue for it. #308

@tdmowrer
Copy link
Contributor

tdmowrer commented Oct 5, 2019

I have a well reproducible crash (UnityGfxDeviceWorker / EXC_BAD_ACCESS) using Unity 2019.2.0f1 and ARFoundation 2.1.1 on iOS 12.3. It happens when you do this (around 50% of time):

arSession.enabled = false; 
arCamera.gameObject.SetActive(false);  // <-- comment this out to prevent crash

If you are not deactivating the arCamera, things seem to work fine. I suspect the pointer to the AR texture is freed by the camera deactivation but ar foundation still is writing / tries to write into it. This would be a thread synchronization problem inside the arkit/arfoundation interface.

I have not yet tried disabling the camera in the next frame...

I am unable to reproduce this. One possible difference is my device is running iOS 13. Have you ever seen the issue in iOS 13 or only in iOS 12.x?

@tdmowrer tdmowrer added the cannot reproduce Unity is unable to reproduce this issue label Oct 7, 2019
@kaij
Copy link

kaij commented Oct 7, 2019

@tdmowrer I can still reproduce this crash with Unity 2019.2.6f1 and iOS 13.1.1. To reproduce, it needs "Multithreaded Rendering" activated. Seems it does not happen as often as with iOS 12.x, but it's definitely still there.
image
PS. ARFoundation 3.0.0 preview 3 (but does not seem related to version of arfoundation)

@tdmowrer
Copy link
Contributor

tdmowrer commented Oct 7, 2019

I've got Unity 2019.2.7f2, ARFoundation 3.0.0-preview.3, iOS 13.1, and multithreaded rendering enabled. In my test, I have a button which does the following:

m_Active = !m_Active;
arSession.enabled = m_Active; 
arCamera.gameObject.SetActive(m_Active);

which is the code you posted earlier. I have tried an iPhone X and iPad Pro. Toggling the session and camera on and off multiple times has the expected behavior and does not crash. Anything else I might be missing to reproduce this?

@NumaNumaNuma
Copy link

NumaNumaNuma commented Oct 8, 2019

I have a well reproducible crash (UnityGfxDeviceWorker / EXC_BAD_ACCESS) using Unity 2019.2.0f1 and ARFoundation 2.1.1 on iOS 12.3. It happens when you do this (around 50% of time). I can still reproduce this crash with Unity 2019.2.6f1 and iOS 13.1.1

I've got Unity 2019.2.7f2, ARFoundation 3.0.0-preview.3, iOS 13.1

Slim chance, and Tim you're probably confident nothing related has changed between these versions, but.. using the exact same setup as him might help? From your 2 responses it looks like you haven't had a chance to try it in similar conditions. For me it definitely happens consistently with anything under preview 3.

@kaij Do you get the problem in one of the arfoundation sample scene too or only your own project?

@tdmowrer
Copy link
Contributor

tdmowrer commented Oct 8, 2019

I have a well reproducible crash (UnityGfxDeviceWorker / EXC_BAD_ACCESS) using Unity 2019.2.0f1 and ARFoundation 2.1.1 on iOS 12.3. It happens when you do this (around 50% of time). I can still reproduce this crash with Unity 2019.2.6f1 and iOS 13.1.1

I've got Unity 2019.2.7f2, ARFoundation 3.0.0-preview.3, iOS 13.1

Slim chance, and Tim you're probably confident nothing related has changed between these versions, but.. using the exact same setup as him might help? :) From your 2 responses it looks like you haven't had a chance to try it in similar conditions. For me it definitely happens consistently with anything under preview 3.

Fair point. This issue was originally reported in ARKit XR Plugin 1.0.0-preview.23 which was largely rewritten in 2.0 and continues to be reported, so it seems unlikely that a point release within 2.1 or 3.0 would matter significantly. Nevertheless, I tested 2019.2.0f1 with ARFoundation 2.1.4 and ARKit XR Plugin 2.1.2 (i.e., the latest stable releases of those packages). My test script toggles the ARSession component and camera's GameObject once per second:

using System.Collections;
using UnityEngine;
using UnityEngine.XR.ARFoundation;

public class CrashieMcCrasherson : MonoBehaviour
{
    public ARSession arSession;
    public ARCameraManager arCameraManager;
    bool m_Active = true;

    void OnEnable()
    {
        StartCoroutine(Toggle());
    }

    IEnumerator Toggle()
    {
        while (true)
        {
            m_Active = !m_Active;
            Debug.Log($"{(m_Active ? "Enabling" : "Disabling")} session and camera");
            arSession.enabled = m_Active;
            arCameraManager.gameObject.SetActive(m_Active);
            yield return new WaitForSeconds(1);
        }
    }
}

This works as expected and fails to reproduce the crash on iOS 13.1 (a version reported to reproduce the problem).

Could someone submit a bug report, attach a minimal project that reproduces the crash, and then post the case number here so I can investigate further?

@tdmowrer
Copy link
Contributor

@OVKHAN This sounds unrelated to the issue being discussed in this thread. Could you open a new issue, please?

@nilsk123
Copy link
Author

nilsk123 commented Nov 2, 2019

@OVKHAN This sounds unrelated to the issue being discussed in this thread. Could you open a new issue, please?

Hi,

Here's a new twist. I can reliably reproduce this in a build that's been downloaded from testflight. The exact same build transfered to a phone using xcode runs just fine on the same device.

@nicholasmaurer
Copy link

nicholasmaurer commented Nov 20, 2019

I have a well reproducible crash (UnityGfxDeviceWorker / EXC_BAD_ACCESS) using Unity 2019.2.0f1 and ARFoundation 2.1.1 on iOS 12.3. It happens when you do this (around 50% of time). I can still reproduce this crash with Unity 2019.2.6f1 and iOS 13.1.1

I've got Unity 2019.2.7f2, ARFoundation 3.0.0-preview.3, iOS 13.1

Slim chance, and Tim you're probably confident nothing related has changed between these versions, but.. using the exact same setup as him might help? :) From your 2 responses it looks like you haven't had a chance to try it in similar conditions. For me it definitely happens consistently with anything under preview 3.

Fair point. This issue was originally reported in ARKit XR Plugin 1.0.0-preview.23 which was largely rewritten in 2.0 and continues to be reported, so it seems unlikely that a point release within 2.1 or 3.0 would matter significantly. Nevertheless, I tested 2019.2.0f1 with ARFoundation 2.1.4 and ARKit XR Plugin 2.1.2 (i.e., the latest stable releases of those packages). My test script toggles the ARSession component and camera's GameObject once per second:

using System.Collections;
using UnityEngine;
using UnityEngine.XR.ARFoundation;

public class CrashieMcCrasherson : MonoBehaviour
{
    public ARSession arSession;
    public ARCameraManager arCameraManager;
    bool m_Active = true;

    void OnEnable()
    {
        StartCoroutine(Toggle());
    }

    IEnumerator Toggle()
    {
        while (true)
        {
            m_Active = !m_Active;
            Debug.Log($"{(m_Active ? "Enabling" : "Disabling")} session and camera");
            arSession.enabled = m_Active;
            arCameraManager.gameObject.SetActive(m_Active);
            yield return new WaitForSeconds(1);
        }
    }
}

This works as expected and fails to reproduce the crash on iOS 13.1 (a version reported to reproduce the problem).

Could someone submit a bug report, attach a minimal project that reproduces the crash, and then post the case number here so I can investigate further?

This script produces a crash intermittently running with:

ARFoundation 2.1.0 - preview 3
ARKit XR Plugin 2.1.0 - preview 5
iOS 12.4.1
Unity 2019.1.3f1
XCode 11.2.1
I've tested on a phone running iOS 13.1.3 which doesn't produce a crash.

@ivatilca
Copy link

Same problem here... crashes right after I import ARCore XR Plugin , then if I try to open the project it crashes after 5 seconds...

@Scottrps
Copy link

This issue still persists in Unity 2019.3.0 with preview7 of ARKit
Starting and stopping an ARSession will reliably(!) cause EXC_BAD_ACCESS.

It doesn't seem to present on all devices though.

We have tested on an iPhoneX with no issue, however an IPad5 did crash using the same build. The iPad was running an older version of iOS ~12 and was updated to 13.3.1 which made no difference to the result.

The solution we've currently found is, as above, un-checking multi-threaded rendering, we have also disabled Compute Skinning and Graphic Jobs (however the builds still crashed if multi-threaded was enabled with these disabled)

@tdmowrer
Copy link
Contributor

Please submit a bug with a project that reproduces the issue, and post the case id here.

@tdmowrer
Copy link
Contributor

Good news! I was finally able to reproduce this - the key was using an old device (an iPhone 6+ in my case).

The fix has been published for 3.1.0-preview.8 with backports to 3.0 (verified) and 2.1 (verified) on the way.

@tdmowrer tdmowrer added bug A bug in an ARFoundation-related package fixed Fixed in newer release and removed cannot reproduce Unity is unable to reproduce this issue labels Mar 12, 2020
@Dak0r
Copy link

Dak0r commented May 19, 2022

Hello!
I'm afraid the issue seems to have returned :/
We get the exact behavior and error that is described here with AR Foundation 4.2.2 (and also 5.0.0 pre) and Unity 2021.3.1f1.

We can reproduce it especially on older devices like the iPad Pro 11" 2nd Gen, but it also happens on current Gen iPad Pros with M1. We can trigger the issues by switching to a different camera (disabling the AR Camera) or by enabling / disabling Occlusion.
It seems that the issue occurs more often, when the iPad is under load, rendering complex objects that cause the framerate to drop. Our code uses DrawMeshInstanced to render some data, if thats relevant?

Disabling Multithreaded Rendering fixes the crashes for us as well, surprisingly we also found that disabling it, improves the performance of our app 🤔

@rdtredinnick
Copy link

I'm also seeing crashes on 2021.3.1f1 (LTS), arfoundation pre-9 when trying to perform the code on the ARFoundation documentation page regarding using command buffers to make a copy of a depth or color or confidence image on the GPU for further processing. I have also tried wittling this down to solely doing a Graphics.Blit or also a Graphics.CopyTexture, but both cases also crash in the Graphics thread, typically in a function called "AddCreatedTexture" for the Blit, or within one called CopyTexture for the Graphics.CopyTexture. Things will typically run for a while (1-2 minutes), but randomly crash, sometimes before then. Don't see it on a debug build, only release. Going to try turning off multi-threaded rendering as well to see what happens.

@rossTnick
Copy link

Following up - disabling multithreaded rendering also fixed the problem.

@novavision
Copy link

In my case I use
Unity 2021.2.19f1
ARFoundation 4.2.3
Addresables 1.19.19

Started to get same error ONLY for release builds on iOS (Android is ocmpletely fine same as iOS dev build) just after unloading the additive scenes. The scene structure looks like that:

Start with main scene (general components + UI manager) > load Additive environment scene with 3D objects and lightning > Load additive AR scene > Load additive level scene.
After that when user leave the level scene and I call unload for level and AR scene I get that crash.

I also can confirm that disabling Multithread Rendering option helped.

Please keep the progress of that issue fix in next versions. Is it related to Unity version or ARFoundadion/Addressables?

@ROBYER1
Copy link

ROBYER1 commented Mar 17, 2023

Since nobody else bothered to do it, I have reported this issue being caused by MultiThreaded Rendering at Unity Bug: IN-35599 - [AR Foundation] MultiThreaded Rendering crash AR Foundation when enable/disable AR Session on iOS+Android

Forum post: https://forum.unity.com/threads/multithreaded-rendering-crash-ar-foundation-when-enable-disable-ar-session.1413507/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug in an ARFoundation-related package fixed Fixed in newer release
Projects
None yet
Development

No branches or pull requests