Crash when trying to use DispatchQueue to run on main thread

1,347 views
Skip to first unread message

Matthew Robinson

unread,
Aug 1, 2014, 3:50:54 AM8/1/14
to rob...@googlegroups.com
Hi,

I'm having some trouble with a simple test application that crashes when trying to make use of DispatchQueue to run some code either synchronously or asynchronously on the main thread. I am building with the 0.15-20140801 snapshot of robovm, and running on an iPhone 4 with iOS 5.1.1.

This is the code in question, which is called in my view's viewWillAppear() method. I am trying to get access to the user accounts, essentially trying to replicate the Twitter functionality here but in Java/Robovm.

            System.out.println("Asking iOS for accounts");
           
final ACAccountType twitterType = accountStore.getAccountType(Accounts.AccountTypeIdentifierTwitter());
            accountStore
.requestAccessToAccounts(twitterType, new VoidBlock2<Boolean, NSError>() {
               
@Override
               
public void invoke(Boolean granted, NSError error) {
                   
if (granted) {
                       
DispatchQueue.getMainQueue().sync(new Runnable() {
                           
@Override
                           
public void run() {
                               
System.out.println("main thread!");
                           
}
                       
});
                   
}
               
}
           
});
           
System.out.println("Done with accounts");


The crash log shows it's not the UI thread (as expected since requestAccessToAccounts will call back on a separate thread). I have annotated (with atos) the addresses that were not automatically symbolicated. If I remove the DispatchQueue block, the VoidBlock happily runs without crashing, so I suspect I have an issue in how I am trying to queue work on the main thread.

Any help much appreciated; I've spent quite a few hours both experimenting and Googleing for answers to no avail.

Crash Log
Thread 5 name:  Dispatch queue: com.apple.root.default-priority
Thread 5 Crashed:
0   libsystem_kernel.dylib            0x3130132c __pthread_kill + 8
1   libsystem_c.dylib                 0x339fe208 pthread_kill + 48
2   libsystem_c.dylib                 0x339f7298 abort + 88
3   twiosreverseauth                  0x0059de40 0x8d000 + 5312064  rvmAbort
4   twiosreverseauth                  0x0059cbf8 0x8d000 + 5307384  rvmRaiseException
5   twiosreverseauth                  0x003284d2 0x8d000 + 2733266  [j]org.robovm.apple.accounts.ACAccountStore$$BlockMarshaler0.invoked(Lorg/robovm/objc/ObjCBlock;ZLorg/robovm/apple/foundation/NSError;)V[callback]
6   Accounts                          0x3391cd1e __block_global_6 + 42
7   libdispatch.dylib                 0x3026ac52 _dispatch_call_block_and_release + 6
8   libdispatch.dylib                 0x302767b4 _dispatch_worker_thread2 + 256
9   libsystem_c.dylib                 0x339b9df4 _pthread_wqthread + 288
10  libsystem_c.dylib                 0x339b9cc8 start_wqthread + 0

 
iPhone Device Log
Aug  1 00:30:37 iPhone UIKitApplication:twiosreverseauth[0xd29d][875] <Notice>: Loading view
Aug  1 00:30:37 iPhone UIKitApplication:twiosreverseauth[0xd29d][875] <Notice>: viewWillAppear()
Aug  1 00:30:37 iPhone UIKitApplication:twiosreverseauth[0xd29d][875] <Notice>: refreshTwitterAccounts() - start
Aug  1 00:30:37 iPhone UIKitApplication:twiosreverseauth[0xd29d][875] <Notice>: Asking iOS for accounts
Aug  1 00:30:37 iPhone UIKitApplication:twiosreverseauth[0xd29d][875] <Notice>: twitterType = Twitter
Aug  1 00:30:37 iPhone UIKitApplication:twiosreverseauth[0xd29d][875] <Notice>: Done with accounts
Aug  1 00:30:37 iPhone UIKitApplication:twiosreverseauth[0xd29d][875] <Notice>: refreshTwitterAccounts() - end
Aug  1 00:30:37 iPhone UIKitApplication:twiosreverseauth[0xd29d][875] <Notice>: viewDidAppear()
Aug  1 00:30:37 iPhone UIKitApplication:twiosreverseauth[0xd29d][875] <Notice>: Unhandled exception: java/lang/UnsatisfiedLinkError
Aug  1 00:30:37 iPhone ReportCrash[876] <Notice>: MS:Notice: Injecting: (null) [ReportCrash] (690.10)
Aug  1 00:30:38 iPhone ReportCrash[876] <Notice>: Formulating crash report for process twiosreverseauth[875]
Aug  1 00:30:38 iPhone com.apple.launchd[1] (UIKitApplication:twiosreverseauth[0xd29d][875]) <Warning>: (UIKitApplication:twiosreverseauth[0xd29d]) Job appears to have crashed: Abort trap: 6
Aug  1 00:30:38 iPhone SpringBoard[61] <Warning>: Application 'twiosreverseauth' exited abnormally with signal 6: Abort trap: 6

 

Niklas Therning

unread,
Aug 1, 2014, 7:45:37 AM8/1/14
to Matthew Robinson, rob...@googlegroups.com
My guess is that the code in the VoidBlock throws an exception. Add a try-catch around everything in the outer block and printStackTrace() to see it. Maybe we can then figure out what is happening.


--
You received this message because you are subscribed to the Google Groups "RoboVM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robovm+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matthew Robinson

unread,
Aug 2, 2014, 1:04:09 AM8/2/14
to rob...@googlegroups.com
Thanks for the tip, but unless I misunderstood what you were suggesting, it has unfortunately provided no additional logs or information. For reference, here is what I did:

            accountStore.requestAccessToAccounts(twitterType, new VoidBlock2<Boolean, NSError>() {
               
@Override
               
public void invoke(Boolean granted, NSError error) {

                   
try {

                       
if (granted) {
                           
DispatchQueue.getMainQueue().sync(new Runnable() {
                               
@Override
                               
public void run() {
                                   
System.out.println("main thread!");
                               
}
                           
});
                       
}

                   
} catch(Exception e) {
                        e
.printStackTrace();
                   
}
               
}
           
});


I also tried the try/catch around the "main thread!" print, to no avail.

Do you have any other tips on how I might go about determining the source of the crash please?

Matthew.

Niklas Therning

unread,
Aug 4, 2014, 3:21:08 AM8/4/14
to Matthew Robinson, rob...@googlegroups.com
Could you perhaps provide a minimal test app that exposes this problem for me to try? Then I might be able to figure out what the problem is.


Matthew Robinson

unread,
Aug 5, 2014, 12:19:14 AM8/5/14
to rob...@googlegroups.com
I have attached a minimal test app that recreates the problem. You'll need to have a Twitter account set up on the iOS device on which you're testing before running this test (and it will ask for permission to access your Twitter account, which you must grant). I was running the test on an iPhone 4 with iOS 5.1.1, but it also crashes on the simulator with iOS 7 (although I confess I haven't checked the logs from the simulator to ensure the crash is identical).

I have built this from Eclipse, but mostly I run my builds from the command line using the "build.sh" script (in particular, because I don't yet have a developer key and am thus using unsigned apps with a Jailbroken iPhone).

I fully accept that I may be doing something wrong here, I'm just stuck knowing where to go net to debug this :-)

Thanks,

Matthew.

On Friday, August 1, 2014 12:50:54 AM UTC-7, Matthew Robinson wrote:
accounts-crash-example.tar.gz

Niklas Therning

unread,
Aug 7, 2014, 10:00:32 AM8/7/14
to Matthew Robinson, rob...@googlegroups.com
Thanks. I've just fixed a bug related to global values like _dispatch_main_q which is what DispatchQueue.getMainQueue() binds to. I can now successfully dispatch async on the main queue.

Please test with the next nightly build (20140808) which will appear on http://download.robovm.org and let me know if it works better.


Matthew Robinson

unread,
Aug 8, 2014, 2:16:12 AM8/8/14
to rob...@googlegroups.com
Thanks for the quick response - it looks like this is solved when running on my simulator (iOS7) - I can successfully run the simple test app I sent you now. I still have a problem on the iPhone 4 with iOS5 with the same "Unhandled exception: java/lang/UnsatisfiedLinkError" as I had in my original report below.

I think it unlikely that I actually need to be able to run on iOS5 (I had been resisting upgrading to have an older OS on which to test), but I am curious if there is anything off hand you know of that could cause problems on this older OS? At some point, I'll move up to iOS7 and test again on the device.

Other than that, thanks again for the quick fix.

On Friday, August 1, 2014 12:50:54 AM UTC-7, Matthew Robinson wrote:

Niklas Therning

unread,
Aug 8, 2014, 4:00:39 AM8/8/14
to Matthew Robinson, rob...@googlegroups.com
The UnsatisfiedLinkError likely comes from calling some method in the CocoaTouch APIs which isn't available under iOS 5. Try to put a try catch in your main() method around everything and catch throwable and print the stack trace. If that catches the UnsatisfiedLinkError you should see the stack trace and be able to figure out the ObjC method which isn't available.


Matthew Robinson

unread,
Aug 15, 2014, 8:09:06 PM8/15/14
to rob...@googlegroups.com, mpr9...@gmail.com
I ended up deciding that supporting iOS 5 was not worthwhile and updated my device (iPhone 4) to iOS 7.1.2. The UnsatisfiedLinkError is now gone, but the simple test application I sent you still crashes on the device as shown below in the sybolicated log (but works fine in the iOS 7.1 and iOS 6.1 simulators). This is built with the 20140815 nightly.

One difference I can think of is that the simulator version is built within Eclipse, but the device version is built on the command line because I need to create an unsigned app for testing. Is there a way to check that my command line is correct (i.e. can Eclipse print out its command line in the console for reference)?

I also noticed that I am no longer getting messages on the device from "System.out.println()" in the Xcode console after updating to 7.1.2. They do appear in the Eclipse console when running in the simulator, though. However, the main issue is still the crashing. Any ideas on how to pursue this would be appreciated, thanks.

Crash Log
Thread 2 Crashed:
0   libsystem_kernel.dylib            0x3bd3a1f0 __pthread_kill + 8
1   libsystem_pthread.dylib           0x3bda4792 pthread_kill + 54
2   libsystem_c.dylib                 0x3bceafd8 abort + 72
3   accountscrash                     0x0060d2e6 0xf8000 + 5329638 (rvmAbort)
4   accountscrash                     0x0060bf3e 0xf8000 + 5324606 (rvmRaiseException)
5   accountscrash                     0x00395b20 0xf8000 + 2743072 ([j]org.robovm.apple.accounts.ACAccountStore$$BlockMarshaler0.invoked(Lorg/robovm/objc/ObjCBlock;ZLorg/robovm/apple/foundation/NSError;)V[callback])
6   libdispatch.dylib                 0x3bc5f830 _dispatch_call_block_and_release + 8
7   libdispatch.dylib                 0x3bc619a6 _dispatch_async_redirect_invoke$VARIANT$up + 106
8   libdispatch.dylib                 0x3bc7291c _dispatch_root_queue_drain + 220
9   libdispatch.dylib                 0x3bc72b1c _dispatch_worker_thread2 + 52
10  libsystem_pthread.dylib           0x3bda1bd0 _pthread_wqthread + 296
11  libsystem_pthread.dylib           0x3bda1a94 start_wqthread + 4

 
Command Line
/Users/mpr/robovm/bin/robovm -verbose -skipsign -config /Users/mpr/src/robovm-apps/accounts-crash-example/robovm.xml -plist /Users/mpr/src/robovm-apps/accounts-crash-example/Info.plist.xml -arch thumbv7 -os ios -cp /Users/mpr/robovm/lib/robovm-rt.jar:/Users/mpr/robovm/lib/robovm-objc.jar:/Users/mpr/robovm/lib/robovm-cocoatouch.jar:/Users/mpr/src/robovm-apps/accounts-crash-example/bin -d out -o accountscrash -createipa accountscrash
Reply all
Reply to author
Forward
0 new messages