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