Unity 3 JIT compile error

I am getting the following error when running my game on an iPad with iOS 4.2.1 created using Unity 3.1.0f4:

“Unhandled Exception: System.ExecutionEngineException: Attempting to JIT compile method ‘(wrapper dynamic-method) Boo.Lang.Runtime.RuntimeServices:RuntimeServices$o p_Addition$System.String$System.String (object,object[ ])’ while running with --aot-only.”

Can anyone tell me how I can figure out what line in my code causes the problem? I looked at the backtrace in GDB and didn’t see anything from my game code listed.

Below is the symbolicated crash log:

Thread 0:
0 libSystem.B.dylib 0x30d30974 kevent + 24
1 libSystem.B.dylib 0x30dda704 _dispatch_mgr_invoke + 88
2 libSystem.B.dylib 0x30dda174 _dispatch_queue_invoke + 96
3 libSystem.B.dylib 0x30dd9b98 _dispatch_worker_thread2 + 120
4 libSystem.B.dylib 0x30d7e24a _pthread_wqthread + 258
5 libSystem.B.dylib 0x30d76970 start_wqthread + 0

Thread 1:
0 libSystem.B.dylib 0x30d04268 mach_msg_trap + 20
1 libSystem.B.dylib 0x30d06354 mach_msg + 44
2 CoreFoundation 0x35802648 __CFRunLoopServiceMachPort + 88
3 CoreFoundation 0x35801ed2 __CFRunLoopRun + 350
4 CoreFoundation 0x35801c80 CFRunLoopRunSpecific + 224
5 CoreFoundation 0x35801b88 CFRunLoopRunInMode + 52
6 WebCore 0x34bf6124 RunWebThread(void*) + 332
7 libSystem.B.dylib 0x30d7d886 _pthread_start + 242
8 libSystem.B.dylib 0x30d72a88 thread_start + 0

Thread 2:
0 libSystem.B.dylib 0x30d042b8 semaphore_wait_trap + 8
1 libSystem.B.dylib 0x30d31b46 semaphore_wait + 2
2 SecretAgentHDFree 0x0089c00c FMOD::SystemI::createChannelGroupInternal(char const*, FMOD::ChannelGroupI**, bool, bool) + 2353772
3 SecretAgentHDFree 0x00800274 FMOD::SystemI::createChannelGroupInternal(char const*, FMOD::ChannelGroupI**, bool, bool) + 1715412
4 SecretAgentHDFree 0x00878de4 FMOD::SystemI::createChannelGroupInternal(char const*, FMOD::ChannelGroupI**, bool, bool) + 2209860
5 SecretAgentHDFree 0x00894448 FMOD::SystemI::createChannelGroupInternal(char const*, FMOD::ChannelGroupI**, bool, bool) + 2322088
6 SecretAgentHDFree 0x008b014c FMOD::SystemI::createChannelGroupInternal(char const*, FMOD::ChannelGroupI**, bool, bool) + 2436012
7 libSystem.B.dylib 0x30d7d886 _pthread_start + 242
8 libSystem.B.dylib 0x30d72a88 thread_start + 0

Thread 3:
0 libSystem.B.dylib 0x30d58770 sem_wait + 12
1 SecretAgentHDFree 0x00645ca0 FMOD_File_SetDiskBusy + 40680
2 SecretAgentHDFree 0x0066540c FMOD::SystemI::createChannelGroupInternal(char const*, FMOD::ChannelGroupI**, bool, bool) + 32364
3 libSystem.B.dylib 0x30d7d886 _pthread_start + 242
4 libSystem.B.dylib 0x30d72a88 thread_start + 0

Thread 4:
0 libSystem.B.dylib 0x30d04268 mach_msg_trap + 20
1 libSystem.B.dylib 0x30d06354 mach_msg + 44
2 AudioToolbox 0x33c0eb96 AURemoteIO::IOThread::Entry(void*) + 54
3 AudioToolbox 0x33b4a1d2 CAPThread::Entry(CAPThread*) + 138
4 libSystem.B.dylib 0x30d7d886 _pthread_start + 242
5 libSystem.B.dylib 0x30d72a88 thread_start + 0

Thread 5:
0 libSystem.B.dylib 0x30d7c9f0 __semwait_signal + 24
1 libSystem.B.dylib 0x30d05e28 nanosleep + 120
2 libSystem.B.dylib 0x30d05d9c usleep + 36
3 SecretAgentHDFree 0x0064578c FMOD_File_SetDiskBusy + 39380
4 SecretAgentHDFree 0x00665440 FMOD::SystemI::createChannelGroupInternal(char const*, FMOD::ChannelGroupI**, bool, bool) + 32416
5 libSystem.B.dylib 0x30d7d886 _pthread_start + 242
6 libSystem.B.dylib 0x30d72a88 thread_start + 0

Thread 6:
0 libSystem.B.dylib 0x30d7c9f0 __semwait_signal + 24
1 libSystem.B.dylib 0x30d05e28 nanosleep + 120
2 SecretAgentHDFree 0x005ad03c start + 5887108
3 SecretAgentHDFree 0x005c4208 start + 5981776
4 SecretAgentHDFree 0x005c4238 start + 5981824
5 SecretAgentHDFree 0x005ad1a8 start + 5887472
6 libSystem.B.dylib 0x30d7d886 _pthread_start + 242
7 libSystem.B.dylib 0x30d72a88 thread_start + 0

Thread 7:
0 libSystem.B.dylib 0x30d7c9f0 __semwait_signal + 24
1 libSystem.B.dylib 0x30d317ec _pthread_cond_wait + 748
2 libSystem.B.dylib 0x30d313d2 pthread_cond_wait + 26
3 Foundation 0x3118e704 -[NSCondition wait] + 164
4 Foundation 0x3117841e -[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:modes:] + 766
5 Foundation 0x3117807a -[NSObject(NSThreadPerformAdditions) performSelectorOnMainThread:withObject:waitUntilDone:] + 94
6 SecretAgentHDFree 0x0000fe6c start + 692
7 Foundation 0x3116c192 -[NSThread main] + 38
8 Foundation 0x31165242 NSThread__main + 966
9 libSystem.B.dylib 0x30d7d886 _pthread_start + 242
10 libSystem.B.dylib 0x30d72a88 thread_start + 0

Thread 8:
0 libSystem.B.dylib 0x30d04268 mach_msg_trap + 20
1 libSystem.B.dylib 0x30d06354 mach_msg + 44
2 CoreFoundation 0x35802648 __CFRunLoopServiceMachPort + 88
3 CoreFoundation 0x35801ed2 __CFRunLoopRun + 350
4 CoreFoundation 0x35801c80 CFRunLoopRunSpecific + 224
5 CoreFoundation 0x35801b88 CFRunLoopRunInMode + 52
6 AudioToolbox 0x33b4a4ba GenericRunLoopThread::RunLoop() + 30
7 AudioToolbox 0x33b5d306 TRunLoop::Entry(void*) + 90
8 AudioToolbox 0x33b4a1d2 CAPThread::Entry(CAPThread*) + 138
9 libSystem.B.dylib 0x30d7d886 _pthread_start + 242
10 libSystem.B.dylib 0x30d72a88 thread_start + 0

Thread 9:
0 libSystem.B.dylib 0x30d7ae54 __sigsuspend_nocancel + 12
1 libSystem.B.dylib 0x30d7ae3e sigsuspend$NOCANCEL + 6
2 libSystem.B.dylib 0x30dd958c _dispatch_sigsuspend + 16
3 libSystem.B.dylib 0x30dd9b98 _dispatch_worker_thread2 + 120
4 libSystem.B.dylib 0x30d7e24a _pthread_wqthread + 258
5 libSystem.B.dylib 0x30d76970 start_wqthread + 0

Unknown thread crashed with unknown flavor: 5, state_count: 1

do you use anything that uses reflection ( can be a json lib where you use direct serialization to and from objects or manual usage of reflection), or generally are you using any 3rd party library?

@dreamora -

I’m using Brady’s Sprite Manager. I’m not using any Json in this game.

Is the following what you mean by reflection?

I don’t have any serialization that I know of.

I did add iAds using Prime31’s plugin.

When I have seen this error it means you are violating the ‘rules’ that need to apply to code that is AOT compiled for iOS. In my experience the limitations stated for Monotouch are effectively the same as Unity on iOS

Monotouch Limitations

One of the more non-obvious ones in my opinion was using value types as keys in Dictionaries.

@tigeba -

Thanks for the limitations link! I’ve been going through the list of limitations but I haven’t been able to find such limitations in my code. Is there a way to get Unity to tell me the line number that is causing the problem?

The monotouch limitations are of no importance commonly.
Unity does not use nor support MonoTouch, it uses its own and monos native functionality only (consequence is that Mono / MonoTouch stuff does not always apply).

@aerende: unhappily no as the error is that deep down that tracing etc is not even present.
Given you don’t use any other 3rd party functionality, start with disabling stripping, potentially you have one of those classes in where U3 at the time fucks up the stripping unhappily

I have to respectfully disagree with dreamora here. The monotouch limitations page are in fact just an enumeration of the limitations of Mono’s AOT capabilities, which in my experience are basically the same for Unity since it is using the same technology.

When I have had a JIT error like that during deploy to the device, I have started commenting out things until I was able to find the culprit. I have not done as much work with iOS since 3.0 came out, so it is possible that that the meaning could have changed.

I don’t disagree that they can apply and widely do or give you an idea of the root of a problem, so its a usefull resource.

But Unity has their own modifications in the mono framework they use, its not off the shelf mono, with all the good and bad consequences of it.

For some limitations its no problem at all for example as they never were supported by unity at all (Unity has a wide variety of things that are technically completely disabled under the hood)

@dreamora -

Disabling stripping didn’t do the trick unfortunately.

Is it OK to do create a new GameObject when a function is called with the iPhone as in the following code? Or is this considered dynamic coding? I am assuming the following is not OK.

function PlaySound(sound : AudioClip, tf : Transform, loop : boolean, volume : float) {

   var soundSource : AudioSource;

   if(gameSounds == 1){

     var soundObject : GameObject = new GameObject("Temporary GameObject (Sound)");

  }
}

Try adding #pragma strict, #pragma implicit, and #pragma downcast to the top of your scripts and fixing the errors that output.

http://forum.unity3d.com/threads/69912-JIT-errors-and-pragmas-to-help

There are a number of ease of use implicit casting being done so that you can worry less about type in Unityscript. Those however do not work on iPhone because it’s not allowed to be JIT compiled.

The error looks similar to this one.
http://answers.unity3d.com/questions/21486/executionengineexception-unity-3-on-the-iphone

Note: This could cause a LOT of errors to pop up in your files, these #pragma s just allow the compiler to throw an error on things that won’t work on the device. So they should be fixed.

Helped for me.
One extra thing I had to do is removing Ani.Mate script that utilizes System.Reflection.Emit which is not available on iOS