iOS: setCallback > ExecutionEngineException: Attempting to JIT compile method

Hi, I’m am using the newly released Unity FMOD integration (1.08.00), and I am trying to replicate the callback for getting Markers and beats from an event instance, as shown in the documentation below.

http://www.fmod.org/documentation/#content/generated/engine_new_unity/script_example_timeline.html

This works fine in the editor and on android, however on iOS, I am getting Just In Time errors when I try to set the callback. Unfortunately the problem seems to be in your dll. Do you know of any work around?

ExecutionEngineException: Attempting to JIT compile method ‘(wrapper
native-to-managed) MainTrackController:BeatEventCallback
(FMOD.Studio.EVENT_CALLBACK_TYPE,intptr,intptr)’ while running with
–aot-only.

at (wrapper managed-to-native)
FMOD.Studio.EventInstance:FMOD_Studio_EventInstance_SetCallback
(intptr,FMOD.Studio.EVENT_CALLBACK,FMOD.Studio.EVENT_CALLBACK_TYPE)
at FMOD.Studio.EventInstance.setCallback (FMOD.Studio.EVENT_CALLBACK
callback, EVENT_CALLBACK_TYPE callbackmask) [0x00000] in :0 at MainTrackController.Play () [0x00000] in :0 at GarageGameController.Begin () [0x00000] in :0

Use IL2CPP for your iOS builds instead of Mono (done on the the Unity Player Settings).

You can’t submit Mono builds to the store anyway because it doesn’t support 64bit apps.

Hi Nicholas, completely forgot about that!

I rebuilt it using IL2CPP, but I now I am getting a MonoPInvokeCallback error.
I’ve looked at Unity specific examples of implemented MonoPInvokeCallback, but I’m unsure how to apply it to your plugin.

NotSupportedException: To marshal a manged method, please add an attribute named ‘MonoPInvokeCallback’ to the method definition.
at FMOD.Studio.EventInstance.FMOD_Studio_EventInstance_SetCallback (IntPtr _event, FMOD.Studio.EVENT_CALLBACK callback, EVENT_CALLBACK_TYPE callbackmask) [0x00000] in :0
at FMOD.Studio.EventInstance.setCallback (FMOD.Studio.EVENT_CALLBACK callback, EVENT_CALLBACK_TYPE callbackmask) [0x00000] in :0
at MainTrackController.Play () [0x00000] in :0
at GarageGameController.Begin () [0x00000] in :0

(Filename: currently not available on il2cpp Line: -1)

You need to add [MonoPInvokeCallback] above your method. It shouldn’t require any changes to our plugin.

MonoPInvokeCallback needs a type specified, at least it does for me… using AOT; What should be used?

I have the same issue still. A type needs to be specified.
Could you provide an example piece of code?

[MonoPInvokeCallback (typeof (FMOD.Studio.EVENT_CALLBACK))]

Side note: this solution also works for getting the FMOD callbacks working on PS4.