Unity application closes suddenly 2-3 times a day

Unity Editor version: 2022.3.54
ML2 OS version: 1.12
Unity SDK version: 2.6.0
Host OS: Windows 10

Hi,
We are developing a medical surgery navigation system with magic leap 2. We completed software development, and we are about to start clinical research for medical certification. But we have one problem which we cannot find why happens. Our unity application suddenly closes without any notification and main menu of ML2 come up. Usually this happens 2-3 times a day. Our application works on both Desktop/Windows and Android Magic Leap. In windows it never shuts down, but on Android this happens if compiled as Android and installed to ML2. The only addition may be using of Vuforia Engine additionally. In desktop, we don't start Vuforia. But in general, we frequently encounter crashes and suddent shutdowns of applications on ML2, which we never encounter in other glasses such as Meta Quest, NReal, etc. For instance deferred rendering and Vuforia together makes ML2 totally freeze, and glasses needs hard-reset, some Unity contents without Vuforia makes ML2 freeze again. Although Vuforia may make it close, we think there is an OS problem also since even without Vuforia we encounter crashes so much, with we Vuforia more crashes. Also I encounted similar problem when I started taking World Camera Image. After sometimes application closes suddenly, when World Camera is activated inside Unity.
For a medical app we need a reliable system and we need to solve this issue. What can be the problem, and how can we fix it?

How can we debug why Vuforia makes apps crash on ML2 ?

Hello,

Sorry about the trouble. There are a few things that you can try to identify the source of the crashes. First, I would suggest collecting an adb bug report immediately after you reproduce the crash. The bug report will contain recent logcat output as well as crash dumps-

Additionally, you should see crash information in logcat-

By the way, Unity debug logging is written to logcat on Android as well so it can be quite helpful for debugging Unity apps in general without resorting to attaching a remote debugger.

If you are able to reliably reproduce the crash, then you could just monitor logcat while the crash occurs to try and get a call stack. If not, then I'd try just grabbing an adb bug report from a device after a crash occurs and see what you can get from that. If you want, I'd be happy to take a look at a bugreport if you are able to collect and send one over.

If there is an issue with Vuforia, then you would need to contact PTC for assistance, but first we can see if we can determine where the crash occurs before presuming the break to be in the Vuforia sdk.

Best,
Adam

1 Like

I am still debuging but recently I just have this from Unity logcat

I have this from Magic Leap Hub 3 (filtered by app name ARBAKO):

02/05/25 16:33:03.768 cameraserver   1047   3386   4330 Camera2ClientBase Closed Camera 1. Client was: com.SimBT.ARBAKO (PID 16224, UID 10123)
02/05/25 16:33:02.716 cameraserver   1047   3386   3386 Camera2ClientBase Closed Camera 0. Client was: com.SimBT.ARBAKO (PID 3409, UID 10123)
02/05/25 16:33:01.712 system_server   1000   3689   4081 WindowManager WIN DEATH: Window{55e39ea u0 com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin}
02/05/25 16:33:01.712 system_server   1000   3689   4081 InputDispatcher Attempted to unregister already unregistered input channel '55e39ea com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin (server)'
02/05/25 16:33:01.712 system_server   1000   3689  22363 ActivityManager Process com.SimBT.ARBAKO (pid 16224) has died: fore TOP 
02/05/25 16:33:01.711 system_server   1000   3689   3802 InputDispatcher channel '55e39ea com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
02/05/25 16:33:01.711 system_server   1000   3689   3802 InputDispatcher channel '55e39ea com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin (server)' ~ Channel is unrecoverably broken and will be disposed!
02/05/25 16:33:01.486 system_server   1000   3689  19337 ActivityTaskManager   Force finishing activity com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin
02/05/25 16:33:00.606 pid-19303  10123  19303  19303 DEBUG       #00 pc 000000000011be5d  /data/app/com.SimBT.ARBAKO-rdK0w4qzqhpFX_wh2_7J2g==/lib/x86_64/libwebrtc.so (OnBatchUpdateEvent(int, void*)+221)

02/05/25 16:33:00.606 pid-19303  10123  19303  19303 DEBUG       #01 pc 000000000118a802  /data/app/com.SimBT.ARBAKO-rdK0w4qzqhpFX_wh2_7J2g==/lib/x86_64/libunity.so (GfxDeviceVK::InsertCustomMarkerCallbackAndDataWithFlags(void (*)(int, void*), int, CustomMarkerCallbackFlags, void*, unsigned long)+162) (BuildId: 796faaf3a8717ccc)

02/05/25 16:33:00.606 pid-19303  10123  19303  19303 DEBUG       #02 pc 00000000012ff273  /data/app/com.SimBT.ARBAKO-rdK0w4qzqhpFX_wh2_7J2g==/lib/x86_64/libunity.so (GfxDeviceWorker::RunCommand(ThreadedStreamBuffer&)+37047) (BuildId: 796faaf3a8717ccc)

02/05/25 16:33:00.606 pid-19303  10123  19303  19303 DEBUG       #03 pc 00000000012f6166  /data/app/com.SimBT.ARBAKO-rdK0w4qzqhpFX_wh2_7J2g==/lib/x86_64/libunity.so (GfxDeviceWorker::RunExt(ThreadedStreamBuffer&)+78) (BuildId: 796faaf3a8717ccc)

02/05/25 16:33:00.606 pid-19303  10123  19303  19303 DEBUG       #04 pc 00000000012f6110  /data/app/com.SimBT.ARBAKO-rdK0w4qzqhpFX_wh2_7J2g==/lib/x86_64/libunity.so (GfxDeviceWorker::Run()+144) (BuildId: 796faaf3a8717ccc)

02/05/25 16:33:00.606 pid-19303  10123  19303  19303 DEBUG       #05 pc 00000000012f5f07  /data/app/com.SimBT.ARBAKO-rdK0w4qzqhpFX_wh2_7J2g==/lib/x86_64/libunity.so (GfxDeviceWorker::RunGfxDeviceWorker(void*)+5) (BuildId: 796faaf3a8717ccc)

02/05/25 16:33:00.606 pid-19303  10123  19303  19303 DEBUG       #06 pc 00000000009a6f06  /data/app/com.SimBT.ARBAKO-rdK0w4qzqhpFX_wh2_7J2g==/lib/x86_64/libunity.so (Thread::RunThreadWrapper(void*)+1222) (BuildId: 796faaf3a8717ccc)

02/05/25 16:33:00.597 pid-19303  10123  19303  19303 DEBUG pid: 16224, tid: 16302, name: UnityGfxDeviceW  >>> com.SimBT.ARBAKO <<<

02/05/25 16:33:00.360 pid-16224  10123  16224  16302 libc Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xffffffff80000008 in tid 16302 (UnityGfxDeviceW), pid 16224 (om.SimBT.ARBAKO)
02/05/25 16:32:59.899 pid-16224  10123  16224  16302 CRASH       #00 pc 000000000011be5d  /data/app/com.SimBT.ARBAKO-rdK0w4qzqhpFX_wh2_7J2g==/lib/x86_64/libwebrtc.so (OnBatchUpdateEvent(int, void*)+221)

02/05/25 16:32:59.899 pid-16224  10123  16224  16302 CRASH       #01 pc 000000000118a802  /data/app/com.SimBT.ARBAKO-rdK0w4qzqhpFX_wh2_7J2g==/lib/x86_64/libunity.so (GfxDeviceVK::InsertCustomMarkerCallbackAndDataWithFlags(void (*)(int, void*), int, CustomMarkerCallbackFlags, void*, unsigned long)+162) (BuildId: 796faaf3a8717ccc)

02/05/25 16:32:59.898 pid-16224  10123  16224  16302 CRASH pid: 16224, tid: 16302, name: UnityGfxDeviceW  >>> com.SimBT.ARBAKO <<<

02/05/25 16:31:23.641 system_server   1000   3689   3710 MagicLeapTaskController onActivityDrawnLocked: com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin isAr=true renderProcessUid=10123
02/05/25 16:31:23.591 system_server   1000   3689   4081 MLWindowManagerHelper Focus is pid 16224 uid 10123 session Session{77de28c 16224:u0a10123} window(AR) mlWindowFlags(0) Window{55e39ea u0 com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin}
02/05/25 16:31:23.466 system_server   1000   3689   3710 MagicLeapTaskController onActivityEnterAnimationCompleteLocked: com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin isAr=true renderProcessUid=10123
02/05/25 16:31:23.466 system_server   1000   3689   3710 MagicLeapTaskController onActivityEnterAnimationCompleteLocked: com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin isAr=true renderProcessUid=10123
02/05/25 16:31:23.425 system_server   1000   3689   3718 ActivityManager Start proc 16224:com.SimBT.ARBAKO/u0a123 for activity {com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin}
02/05/25 16:31:23.381 system_server   1000   3689   4081 ActivityTaskManager START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10210000 cmp=com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin} from uid 10061
02/05/25 16:31:08.878 system_server   1000   3689   3705 WindowManager WIN DEATH: Window{49cec58 u0 com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin}
02/05/25 16:31:08.708 system_server   1000   3689   3710 ActivityManager Killing 15201:com.SimBT.ARBAKO/u0a123 (adj 905): remove task
02/05/25 16:31:06.341 system_server   1000   3689   3710 ActivityTaskManager Activity pause timeout for ActivityRecord{e4a655b u0 com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin t161}
02/05/25 16:30:28.640 system_server   1000   3689   3710 MagicLeapTaskController onActivityDrawnLocked: com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin isAr=true renderProcessUid=10123
02/05/25 16:30:28.500 system_server   1000   3689   6131 MLWindowManagerHelper Focus is pid 15201 uid 10123 session Session{fe527ca 15201:u0a10123} window(AR) mlWindowFlags(0) Window{49cec58 u0 com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin}
02/05/25 16:30:28.326 system_server   1000   3689   3710 MagicLeapTaskController onActivityEnterAnimationCompleteLocked: com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin isAr=true renderProcessUid=10123
02/05/25 16:30:28.326 system_server   1000   3689   3710 MagicLeapTaskController onActivityEnterAnimationCompleteLocked: com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin isAr=true renderProcessUid=10123
02/05/25 16:30:28.210 system_server   1000   3689   3718 ActivityManager Start proc 15201:com.SimBT.ARBAKO/u0a123 for activity {com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin}
02/05/25 16:30:28.160 system_server   1000   3689   6131 ActivityTaskManager START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10210000 cmp=com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin} from uid 10061
02/05/25 16:30:16.429 system_server   1000   3689   6131 WindowManager WIN DEATH: Window{c86f553 u0 com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin}
02/05/25 16:30:16.202 system_server   1000   3689   3710 ActivityManager Killing 26837:com.SimBT.ARBAKO/u0a123 (adj 905): remove task
02/05/25 16:30:13.031 system_server   1000   3689   3710 ActivityTaskManager Activity pause timeout for ActivityRecord{71289e2 u0 com.SimBT.ARBAKO/com.hyeon.bluetoothPlugin.BluetoothPlugin t160}

When we track reason in time order:

  1. First Vulkan graphic raised an error from libunity.so
  2. Than Unity Webrtc raised an error from libwebrtc.so
  3. Finally com.hyeon.bluetoothPlugin.BluetoothPlugin raised an error from Magic Leap Controller and system crashed finally at that point.

I think crash from Magic Leap Controller. I see similar crash behaviour while not using Webrtc in the past. So Vulkan Graphics and Magic Leap Controller are more likely.

ChatGPT says following possible multiple reasons (which probably not from our source code):

WebRTC-Related Crash
Likely Cause:
WebRTC might be handling an invalid memory address due to incorrect threading or event updates.

Vulkan API (GfxDeviceVK) Rendering Crash
Likely Cause:
Vulkan API’s GfxDeviceVK is failing during InsertCustomMarkerCallbackAndDataWithFlags().
Threaded rendering may be leading to an unexpected memory violation.
Potential Fixes:

Bluetooth Plugin Conflict
Likely Cause:
com.hyeon.bluetoothPlugin.BluetoothPlugin might be conflicting with Magic Leap’s AR system.
Bluetooth device access might be triggering an issue in WebRTC or Vulkan rendering.

Yea, let’s see. Thanks for providing some log snippets. We won’t be able to debug your code directly, but maybe we can offer some suggestions-

There are enough components at play here that you may need to systematically disable dependencies (webrtc, bluetooth plugin, vuforia, world cam feeds, etc.) to isolate the problem.

What is com.hyeon.bluetoothPlugin.BluetoothPlugin? Is that your own bluetooth api wrapper and is it using a separate Android activity from your main app activity? I’m curious if you’re managing the lifecycle of multiple activities.

One thing that you could try is disabling multithreaded rendering. The issue may be outside of code that Magic Leap would have visibility into. (unity/webrtc) However, based on the stacks you provided, I wonder if you might notice a difference with multithreaded rendering disabled- (the option is in Project settings → Player → Android tab → Other Settings)

Best,
Adam

I disabled Multi-threaded rendering, it made application more stable at least for our medical project.

But ML2 still crashes very frequently with different Unity contents, which is not so good, I am strongly convinced that ML2 hardware drivers are not working reliably and crashes so easily. Let me give other samples below that work with simple other glasses smoothly (like NReal, Meta Quest 2, Meta Quest 3), but crashing with ML2. All the above 6 samples works without any problem with other glasses, but not with ML2.

  1. I developed a shoot-em-up game with aircrafts flying on a terrain and shooting, it only uses some visual effects and a large terrain decorated with objects, nothing more. ML crashes and closed, even after the app is closed, hardware errors continued, and USB connection gone, I have to restart the glasses.

  2. We developed a advance fire fighting simulator, it has a building model, NavMesh and moving characters, again app crashes immediately even simulation is not yet started, glasses gone again, usb connection disconnected, never come back again, so I restart it again.

  3. Applications using native memory crashes very frequently.

  4. Applications using deferred rendering crashes very frequently.

  5. Applications using multi-threaded rendering crashes very frequently.

  6. When I use Agora video chat SDK, it crashes again while initializing Agora, even after the app is closed, hardware errors continue, I have to restart the glasses. The below text is showing the crash and after the application is all closed, many hardware errors are continue, so I restart glasses again.

ML2-Crash-logs-2025-02-18-19-15-20.txt (1.1 MB)

I’m sorry to hear that you are running into issues. did you notice the issue on the Magic Leap Examples project. You may need to inspect the logs to see if one or more of your implementations are causing the device to run out of resources or cause the application to crash.

If you suspect that the issue is due to the Agora plugin, you may need to reach out to their support directly.

Hi,

Since I start using ML2, I am opening many issues which are almost all about crashes and hardware problems, I did not have such high number of issues in different glasses I used in more than 10 years. You are asking if samples are working, but they will of course be working, since if they were not working you will have no change to release your product. Samples working does not always mean application is having bugs, and there is no hardware/software problems in the system in different usage conditions.

As I already mention, there is no single crashing issue (note: I am using old ML SDK, not OpenXR). I am getting crashes from many different independent issues frequently, sometimes randomly, sometime consistently, even a few days ago ML2 crashed while switching GlobalDimmerValue from 1 to 0, which is for sure pure 2 lines of code of ML2 SDK (MLGlobalDimmer.SetValue(0,false) and MLSegmentedDimmer.Deactivate() methods). When a crash occurs, sometimes device restarts it self, sometimes application closes and OS starts working inconsistently, USB connection lost, Bluetooth gone, controller not working, which shall not be normal for an OS and device. An application shall not crash an entire OS or device so easily.

Also some crashes are not time depended, not consuming resources in time. ML2 consistently crashes in some specific contents/functions of Unity every time in just a second immediately, which all works in Windows, NReal, Meta Quest 2, Meta Quest 3 and Mobile Phones. I fixed some of these crashes several times searching for what makes the crashes and nothing I fixed was a bug for sure, I had to remove some functionality/code to fix crashes although they are not bugs. I am a 35 year expert software developer and CTO of a 70 people company, so I am not a junior that will do such many bugs easily. I thing you need to consider examining your device, OS and SDK for failures in different use cases.

As I see our problem may be the same as the one in below. We are also using MLCamera since we have to use it (vuforia does only work with MLCamera prefab in packages). We also use webrtc at the same time. When we turn off multi threaded rendering crashes reduced significanly in our medical app, but other apps still have crash issues.

1 Like