ERR_INVALID_HANDLE at EventInstance stop

Hi, whenever I try to call FMOD.Studio.STOP_MODE to stop the music I’m playing in-game, I receive an ERR_INVALID_HANDLE. Whether I initialize my music in a script or on an object with a Studio Event Emitter, this error pops up. I’m pretty new to FMOD, so I’m not sure how to fix this.

I’m using this to output the result:

        FMOD.RESULT result;
        result = musicEventInstance.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);

#if UNITY_EDITOR
Debug.Log(result);

        if (result != FMOD.RESULT.OK)
        {
            Debug.Break();
        }

#endif

That result indicates that your event instance’s handle is invalid, likely because musicEventInstance hasn’t been created yet, or because it has already been released by the FMOD system.

A few things:

  • What versions of FMOD and Unity are you using?
  • Can I get you to set your logging level to “log”, enable API error logging, and post a log from Unity where this issue occurs?
  • Can I get you to post the full script, or a stripped down version of it where you can reproduce the issue, here for me to take a look at?

Hi, it’s suddenly working for some reason, but I’m suspicious, so let me send some stuff anyway. I’m using the most recent versions of FMOD and Unity, to my knowledge.

[FMOD] EventInstance::stop(1) returned ERR_INVALID_HANDLE for STUDIO_EVENTINSTANCE (0x0).
UnityEngine.Debug:LogError (object)
FMODUnity.RuntimeUtils:DebugLogError (string) (at Assets/Plugins/FMOD/src/RuntimeUtils.cs:580)
FMODUnity.RuntimeManager:ERROR_CALLBACK (intptr,FMOD.SYSTEM_CALLBACK_TYPE,intptr,intptr,intptr) (at Assets/Plugins/FMOD/src/RuntimeManager.cs:142)
FMOD.Studio.EventInstance:stop (FMOD.Studio.STOP_MODE) (at Assets/Plugins/FMOD/src/fmod_studio.cs:1377)
AudioManager:StopAudio (bool) (at Assets/Scripts/Audio/AudioManager.cs:99)
InkManager:OnDestroy () (at Assets/Scripts/Managers Courtroom Lobby/InkManager.cs:537)

This is the error I’m getting, though now it’s appearing in a different place.

Essentially I’m triggering the FMOD tracks from a series of tags in a story engine, so I trigger InitializeMusic() at the start of the game:

public void InitializeMusic(EventReference musicEventReference)
{
musicEventInstance = CreateInstance(musicEventReference);
musicEventInstance.start();
}

Then if I want to trigger to stop the audio, it’ll go to one of these methods:

public void StopAudio(bool fade)
{
if (fade == true)
{
musicEventInstance.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
}
else if (fade == false)
{
musicEventInstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
}
}

public void PauseAudio(bool pause)
{
musicEventInstance.setPaused(pause);
}

Thank you for your help!!

It’s stopped working again! I’m super confused. I tried going to the PauseAudio() method, which was working for a bit, but not anymore. I got this error at the time I tried to call for pause:

[FMOD] EventInstance::setPaused(true) returned ERR_INVALID_HANDLE for STUDIO_EVENTINSTANCE (0x0).
UnityEngine.Debug:LogError (object)
FMODUnity.RuntimeUtils:DebugLogError (string) (at Assets/Plugins/FMOD/src/RuntimeUtils.cs:580)
FMODUnity.RuntimeManager:ERROR_CALLBACK (intptr,FMOD.SYSTEM_CALLBACK_TYPE,intptr,intptr,intptr) (at Assets/Plugins/FMOD/src/RuntimeManager.cs:142)
FMOD.Studio.EventInstance:setPaused (bool) (at Assets/Plugins/FMOD/src/fmod_studio.cs:1369)
AudioManager:PauseAudio (bool) (at Assets/Scripts/Audio/AudioManager.cs:105)
InkManager:HandleTags (System.Collections.Generic.List`1) (at Assets/Scripts/InkManager.cs:423)
InkManager:ContinueStory () (at Assets/Scripts/InkManager.cs:162)
InkManager:MakeChoice (int) (at Assets/Scripts/InkManager.cs:533)
UnityEngine.EventSystems.EventSystem:Update () (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:530)

This is what the whole log looks like after the track I’m attempting to pause plays:

Hi,

Thank you for the code and the screenshots.

Could you please collect a profiler capture while reproducing this issue in the game, then package your profiler session including banks (ensure to tick the “Banks” option when exporting), and upload it to your FMOD Profile? In the profiler recording, we will want to keep an eye on the event instance lifespans:

In your code is musicEventInstance.release() being called anywhere?

To prevent these function calls from causing errors, you might want to implement an EventInstance::isValid() check:

if (musicEventInstance.isValid())
{
	if (fade == true)
	{
		musicEventInstance.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
	}
	else if (fade == false)
	{
		musicEventInstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
	}
}
else
{
	Debug.Log("Failed to stop 'musicEventInstance' as it is invalid");
}

This won’t solve the error but will allow you to control the logging better.