Skip to content

My app is crashing without a stacktrace, what should I do?

florianf edited this page Nov 2, 2016 · 3 revisions

If your app is crashing without a stacktrace, get your device logs via the device manager of XCode.

You should see something like this (only relevant parts shown):

Exception Type: EXC_CRASH (SIGSEGV)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread: 1

Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0:
0 libobjc.A.dylib 0x32bb8f47 objc_msgSend + 7
1 CoreBluetooth 0x242f4503 -[CBCentralManager handlePeripheralDiscovered:] + 731
2 CoreBluetooth 0x242f4997 -[CBCentralManager xpcConnection:didReceiveMsg:args:] + 63
3 CoreBluetooth 0x242ff2bb __34-[CBXpcConnection handleMsg:args:]_block_invoke + 51
4 libdispatch.dylib 0x331172e1 _dispatch_call_block_and_release + 9
5 libdispatch.dylib 0x331172cd _dispatch_client_callout + 21
6 libdispatch.dylib 0x3311f725 _dispatch_queue_drain + 1465
7 libdispatch.dylib 0x33119aa9 _dispatch_queue_invoke + 81
8 libdispatch.dylib 0x3311a987 _dispatch_main_queue_callback_4CF + 395
9 CoreFoundation 0x245f6605 CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 5
10 CoreFoundation 0x245f4d05 __CFRunLoopRun + 1509
11 CoreFoundation 0x245411fd CFRunLoopRunSpecific + 473
12 CoreFoundation 0x2454100f CFRunLoopRunInMode + 103
13 GraphicsServices 0x2bdda1fd GSEventRunModal + 133
14 UIKit 0x27ce5a55 UIApplicationMain + 1437
15 IOSLauncher 0x0081e9d3 [J]org.robovm.apple.uikit.UIApplication.main(ILorg/robovm/rt/bro/ptr/BytePtr$BytePtrPtr;Ljava/lang/String;Ljava/lang/String;)I + 167
16 IOSLauncher 0x0081e033 [J]org.robovm.apple.uikit.UIApplication.main([Ljava/lang/String;Ljava/lang/Class;Ljava/lang/Class;)V + 535
17 IOSLauncher 0x0081d5ff [j]org.robovm.apple.uikit.UIApplication.main([Ljava/lang/String;Ljava/lang/Class;Ljava/lang/Class;)V[clinit] + 51
18 IOSLauncher 0x003ffbff [J]com.isaigu.faner.hygienekey.IOSLauncher.main([Ljava/lang/String;)V + 59
19 IOSLauncher 0x009a6471 _call0 + 45
20 IOSLauncher 0x0099f2b3 callVoidMethod + 105
21 IOSLauncher 0x009a0ded rvmCallVoidClassMethodA + 181
22 IOSLauncher 0x009a0e3f rvmCallVoidClassMethod + 17
23 IOSLauncher 0x0099b15f rvmRun + 177
24 IOSLauncher 0x00993427 main + 293
25 libdyld.dylib 0x33138aad start + 1

Thread 1 Crashed:
0 libsystem_kernel.dylib 0x33202b2c __psynch_cvwait + 24
1 libsystem_pthread.dylib 0x33280385 _pthread_cond_wait + 517
2 libsystem_pthread.dylib 0x33281269 pthread_cond_wait + 37
3 IOSLauncher 0x009ba9a9 GC_wait_marker + 25
4 IOSLauncher 0x009b49cd GC_help_marker + 135
5 IOSLauncher 0x009b962b GC_mark_thread + 211
6 libsystem_pthread.dylib 0x33280e21 _pthread_body + 137
7 libsystem_pthread.dylib 0x33280d93 _pthread_start + 115
8 libsystem_pthread.dylib 0x3327eb1c thread_start + 4

That means that the GC Thread (Thread 1) crashed, while the main thread executed the method [CBCentralManager handlePeripheralDiscovered]. The issue here is, that the CBCentralManager calls a method on the CBCentralManagerDelegate delegate, but the delegate was already GC'ed on the Java side.

To fix this issue, add a strong ref to the delegate, via f.ex. cbcManagerInstance.addStrongRef(cbcDelegate) so it won't be garbage collected on the Java side. The addStrongRef method is available for every class that extends ObjCObject.

This happens when you pass delegates directly into a constructor, f.ex. new CBCentralManager(new CBCentralManagerDelegateAdapter(), null); if the delegate is passed via setDelegate(new CBCentralManagerDelegateAdapter()) the strong ref is added automatically.