Crash with programmer sounds on PS4

Hi all,
We are trying to make our project (that is running smoothly on PC) works on PS4. We are working with Unity 5.5.4p5 and FMOD 1.10.
The problem occurs when we receive a programmer sound callback. We have managed to track down the line that is making the game crash on PS4:

var soundResult = FMODUnity.RuntimeManager.LowlevelSystem.createSound (
dialogueSoundInfo.name_or_data, dialogueSoundInfo.mode, ref dialogueSoundInfo.exinfo, out dialogueSound);

In the PS4 Console Output we get this error:

C:/buildslave/unity/build/Tools/il2cpp/il2cpp/libil2cpp/vm/PlatformInvoke.cpp(382) : 
Assertion Failed (d->method->methodDefinition) in function MarshalDelegate

This is the whole callback code:

[AOT.MonoPInvokeCallback (typeof(FMOD.Studio.EVENT_CALLBACK))]
private static FMOD.RESULT  DialogueEventCallback(
	FMOD.Studio.EVENT_CALLBACK_TYPE type,
	FMOD.Studio.EventInstance instance, IntPtr parameterPtr)
{ // Retrieve the user data
	IntPtr stringPtr;
	instance.getUserData (out stringPtr);

	// Get the string object
	GCHandle stringHandle = GCHandle.FromIntPtr (stringPtr);
	String key = stringHandle.Target as String;

	switch (type)
	{
	case FMOD.Studio.EVENT_CALLBACK_TYPE.CREATE_PROGRAMMER_SOUND:
		FMOD.Studio.SOUND_INFO dialogueSoundInfo;

		var parameters = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure (parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES));
		var keyResult = FMODUnity.RuntimeManager.StudioSystem.getSoundInfo (key, out dialogueSoundInfo);
		if (keyResult != FMOD.RESULT.OK)
		{
			break;
		}

		FMOD.Sound dialogueSound;
		var soundResult = FMODUnity.RuntimeManager.LowlevelSystem.createSound (dialogueSoundInfo.name_or_data, dialogueSoundInfo.mode, ref dialogueSoundInfo.exinfo, out dialogueSound);
		if (soundResult == FMOD.RESULT.OK)
		{
			parameters.sound = dialogueSound.handle;
			parameters.subsoundIndex = dialogueSoundInfo.subsoundindex;
			Marshal.StructureToPtr (parameters, parameterPtr, false);
		}
		break;
	[...]
}

I can’t understand what we are doing wrong and if it’s a problem related to how we have implemented programmer sound.

Thanks for your support,
Simone

Does this only occur in development builds or release builds too?

This occurs in both development and release builds.
I’ve just tested a release build and i get the same error:
C:/buildslave/unity/build/Tools/il2cpp/il2cpp/libil2cpp/vm/PlatformInvoke.cpp(382) : Assertion Failed (d->method->methodDefinition) in function MarshalDelegate

This occurs in both development and release builds.
I’ve just tested a release build and i get the same error:
C:/buildslave/unity/build/Tools/il2cpp/il2cpp/libil2cpp/vm/PlatformInvoke.cpp(382) : Assertion Failed (d->method->methodDefinition) in function MarshalDelegate

We are still investigating this on our end, so far we are only able to reproduce this on PS4 which leads us to believe it is an issue with PS4 and Mono.

One way to avoid this is to use the IL2CPP scripting backend, which can be changed in the Unity Player Settings menu. Using this then does not require the ‘MonoPInvokeCallback’ before the function.

The other option is to use SYNCHRONOUS_UPDATE when initializing FMOD.Studio, this will disable asynchronous processing and perform all processing on the calling thread instead.
More information about the FMOD Threading modes can be found here:
https://www.fmod.org/docs/content/generated/overview/studio_thread.html

I alredy tried using both Mono and IL2CPP. I tried removing ‘MonoPInvokeCallback’ in IL2CPP and we got this error:

“NotSupportedException: To marshal a managed 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)”.

I tried the other solution to. Not sure where to define SYNCHRONOUS_UPDATE. I’ve put 'FMOD_STUDIO_INIT_SYNCHRONOUS_UPDATE ’ in the PlayerSettings but didn’t work, so I added this command

“studioInitFlags |= FMOD.Studio.INITFLAGS.SYNCHRONOUS_UPDATE;”

at the script RuntimeManager.cs at line 202, but didn’t work either. The error is always the one that I’ve put in the first post.