ERR_MEMORY : Not enough memory or resources

To update did just that, using the underlying Editor and the problem is still happening.

That is very very strange. Are you able to post your crash logs for us to look at?

Definitely! Thanks for being active on this issue. Here is one:

Thank you for the crash logs. I passed them onto our development team and they’re asking if you are setting any event callbacks. The crash looks like it’s happening in the FMOD_STUDIO_EVENT_CALLBACK_TIMELINE_MARKER callback (judging from the error [AOT.MonoPInvokeCallback(typeof(FMOD.Studio.EVENT_CALLBACK))].

Thanks for the updates. I’m using that for a time-based trigger, following this FMOD tutorial:
https://www.fmod.com/resources/documentation-unity?version=2.0&page=examples-timeline-callbacks.html

This has been there for a while:

		/// <summary>
		/// When we start the radio, we ALSO start a timelineInfo that will tell us the LAST 'Destination marker' that was hit on the timeline (e.g. 'timingSongStart' and timingSongEnd').
		/// </summary>
		public void StartRadioMusic(){
			timelineInfo = new TimelineInfo();

			// Explicitly create the delegate object and assign it to a member so it doesn't get freed
			// by the garbage collected while it's being used
			beatCallback = new FMOD.Studio.EVENT_CALLBACK(ToolsAudio.BeatEventCallback);

			// Pin the class that will store the data modified during the callback
			timelineHandle = GCHandle.Alloc(timelineInfo, GCHandleType.Pinned);

			// Pass the object through the userdata of the instance
			musicInstance.eventInstance.setUserData(GCHandle.ToIntPtr(timelineHandle));

			musicInstance.eventInstance.setCallback(beatCallback, FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_BEAT | FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_MARKER);

			ToolsAudio.PlayAudioEvent(musicInstance, parentObject);
			musicInstance.eventInstance.setVolume(0);
		}

And here is the actual BeatEventCallBack

	[AOT.MonoPInvokeCallback(typeof(FMOD.Studio.EVENT_CALLBACK))]
    //public static FMOD.RESULT BeatEventCallback(FMOD.Studio.EVENT_CALLBNoACK_TYPE type, FMOD.Studio.EventInstance instance, IntPtr parameterPtr){
	public static FMOD.RESULT BeatEventCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, IntPtr instancePtr, IntPtr parameterPtr){
        // Retrieve the user data
        IntPtr timelineInfoPtr;
		FMOD.Studio.EventInstance instance = new FMOD.Studio.EventInstance(instancePtr);
		instance.getUserData(out timelineInfoPtr);

        // Get the object to store beat and marker details
        GCHandle timelineHandle = GCHandle.FromIntPtr(timelineInfoPtr);
        TimelineInfo timelineInfo = (TimelineInfo)timelineHandle.Target;

        switch (type){
            case FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_BEAT:
                {
                    var parameter = (FMOD.Studio.TIMELINE_BEAT_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.TIMELINE_BEAT_PROPERTIES));
                    timelineInfo.currentMusicBar = parameter.bar;
                }
                break;

            case FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_MARKER:
                {
                    var parameter = (FMOD.Studio.TIMELINE_MARKER_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.TIMELINE_MARKER_PROPERTIES));
                    timelineInfo.lastMarker = parameter.name;
                }
                break;
        }
        return FMOD.RESULT.OK;
    }

And recently, our porting team added this new entry to a programmer sound event callback, because we were getting errors on XboxOne:

	//Added MonoPInvokeCallback attribute to fix the NotSupportedException error on XboxOne builds.
	[AOT.MonoPInvokeCallback(typeof(FMOD.Studio.EVENT_CALLBACK))]
	public static FMOD.RESULT DialogueEventCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, IntPtr instancePtr, IntPtr parameterPtr) {
		// Retrieve the user data
		IntPtr stringPtr;
		FMOD.Studio.EventInstance instance = new FMOD.Studio.EventInstance(instancePtr);
		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:
                {
                    var parameter = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES));
                    FMOD.Studio.SOUND_INFO dialogueSoundInfo;
                    var keyResult = RuntimeManager.StudioSystem.getSoundInfo(key, out dialogueSoundInfo);
                   
					if (keyResult != FMOD.RESULT.OK){
                        break;
                    }

					//Debug.Log("dialogueSoundInfo: " + dialogueSoundInfo.name_or_data);

                    FMOD.Sound dialogueSound;
                    //FMOD 1.10
					//var soundResult = RuntimeManager.LowlevelSystem.createSound(dialogueSoundInfo.name_or_data, dialogueSoundInfo.mode, ref dialogueSoundInfo.exinfo, out dialogueSound);
					var soundResult = RuntimeManager.CoreSystem.createSound(dialogueSoundInfo.name_or_data, dialogueSoundInfo.mode, ref dialogueSoundInfo.exinfo, out dialogueSound);

					if (soundResult == FMOD.RESULT.OK){
                        parameter.sound = dialogueSound.handle;
                        parameter.subsoundIndex = dialogueSoundInfo.subsoundindex;
                        Marshal.StructureToPtr(parameter, parameterPtr, false);
                    }
                }
                break;

            case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROY_PROGRAMMER_SOUND:
                {
                    var parameter = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES));
                    var sound = new FMOD.Sound();
                    sound.handle = parameter.sound;
                    sound.release();
                }
                break;

            case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROYED:
                // Now the event has been destroyed, unpin the string memory so it can be garbage collected
                stringHandle.Free();
                break;
        }

        return FMOD.RESULT.OK;
    }

And here is the error below:

(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 35)
NotSupportedException: To marshal a managed method, please add an attribute named 'MonoPInvokeCallback' to the method definition. The method we're attempting to marshal is: ToolsAudio::DialogueEventCallback
  at FMOD.Studio.EventInstance.FMOD_Studio_EventInstance_SetCallback (System.IntPtr _event, FMOD.Studio.EVENT_CALLBACK callback, FMOD.Studio.EVENT_CALLBACK_TYPE callbackmask) [0x00000] in <00000000000000000000000000000000>:0

I did comment the porting team one out and still get the crashes. Can I comment the first one out? Would the dialogue event still work?

Hi @richard, here is another crash log. This one just happened, and I had already commented out the Event_Callback for the Xbox stuff:

Hey Richard, any updates on this? It’s a huge struggle to constantly restart Unity for these crashes. It’s slowing down the project and becoming extremely frustrating.

Our development team noticed this null checker was missing from your code (just after IntPtr stringPtr;)

    FMOD.RESULT result = instance.getUserData(out timelineInfoPtr);
    if (result != FMOD.RESULT.OK)
    {
        Debug.LogError("Timeline Callback error: " + result);
    }

Could you put this null checker back in and see if this helps?

As for their xbox callback error - it’s hard to tell without more information. It looks like Unity is complaining that [AOT.MonoPInvokeCallback(typeof(FMOD.Studio.EVENT_CALLBACK))] is missing, but its there, so something else is likely amiss.

Also to be clear there are other symptoms/crashes with FMOD:

  • 90% of the time, after doing a Play/Stop, the music/background sounds will keep playing in the editor. I can still work but when I press Play again, it freezes
  • Some other times, I can do 2 or 3 Play/Stop, and then it usually ‘hangs’ when coming back to the editor. Or if it doesn’t hang, we get the same issues as above (music keeps playing in Editor and then freezes when I press Play again)
  • Every so often it actually crashes Unity, which is when I provide you with the crash log.

Now this is happening EVERY DAY, every 30 minute or less. So if you want to jump on a call or a skype or whatever, I can easily reproduce it.
And once again, we are close to shipping and doing bugfixing, so a LOT of Play/Stop and time wasted. Having some help here would be AMAZING.

1 Like

The most recent crash report you’ve provided shows that the crash is happening in the timeline marker callback as indicated previously. Looking at the callstack leading to that crash, I can see this callback is being fired after the scene has been torn down, which means the EventInstance was never stopped / released.

EventInstances that are part of a Studio Event Emitter should be cleaned up via the OnDestroy method of that mono behavior, however it’s possible (through scripting) you are creating instances also. If this is the case make sure you clean up your Event instances. If you don’t clean them up, FMOD will do it for you, but it will also fire any deferred callbacks as it cleans up, which might be too late if say your timelineInfo managed data has already been released or the callback delegate is gone (causing a crash).

For everyone experiencing this issue:

I was getting this error too. Turns out I was carelessly calling stuff on the RuntimeManager during EditMode. The Unity plugin won’t stop you from doing so.
If you - for example - need to get a guid at editor time you will need to use the EditorSystem respectively the EventCache.

Maybe this will be of help for anyone.

I’ve been getting memory leak issues too, specifically from using fmod with unitys timeline.