# ERR\_INVALID\_HANDLE at EventInstance stop

**URL:** <https://qa.fmod.com/t/err-invalid-handle-at-eventinstance-stop/21863>\
**Category:** Unity\
**Created:** [July 10, 2024, 3:36pm UTC](https://qa.fmod.com/t/err-invalid-handle-at-eventinstance-stop/21863 "2024-07-10T15:36:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![eseravas](https://avatars.discourse-cdn.com/v4/letter/e/eb9ed0/32.png) [@eseravas](https://qa.fmod.com/u/eseravas)\
**Post date:** [July 10, 2024, 3:36pm UTC](https://qa.fmod.com/t/err-invalid-handle-at-eventinstance-stop/21863/1 "2024-07-10T15:36:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [July 12, 2024, 6:15am UTC](https://qa.fmod.com/t/err-invalid-handle-at-eventinstance-stop/21863/2 "2024-07-12T06:15:24Z")

</div>

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](https://www.fmod.com/docs/2.02/unity/settings.html#logging-level) to “log”, enable [API error logging](https://www.fmod.com/docs/2.02/unity/settings.html#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?

---

<div class="post-metadata">

**Author:** ![eseravas](https://avatars.discourse-cdn.com/v4/letter/e/eb9ed0/32.png) [@eseravas](https://qa.fmod.com/u/eseravas)\
**Post date:** [July 12, 2024, 2:10pm UTC](https://qa.fmod.com/t/err-invalid-handle-at-eventinstance-stop/21863/3 "2024-07-12T14:10:50Z")

</div>

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!!

---

<div class="post-metadata">

**Author:** ![eseravas](https://avatars.discourse-cdn.com/v4/letter/e/eb9ed0/32.png) [@eseravas](https://qa.fmod.com/u/eseravas)\
**Post date:** [July 12, 2024, 3:06pm UTC](https://qa.fmod.com/t/err-invalid-handle-at-eventinstance-stop/21863/4 "2024-07-12T15:06:30Z")

</div>

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:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/d/d55b4872e9589926eaf88d8f8a380e5f9121825d.png)

---

<div class="post-metadata">

**Author:** ![eseravas](https://avatars.discourse-cdn.com/v4/letter/e/eb9ed0/32.png) [@eseravas](https://qa.fmod.com/u/eseravas)\
**Post date:** [July 12, 2024, 3:17pm UTC](https://qa.fmod.com/t/err-invalid-handle-at-eventinstance-stop/21863/5 "2024-07-12T15:17:00Z")

</div>

![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/e/e332adb711ee28c9c304fb6db46cba1ccc0a78f2.png)

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [July 16, 2024, 3:55am UTC](https://qa.fmod.com/t/err-invalid-handle-at-eventinstance-stop/21863/6 "2024-07-16T03:55:53Z")

</div>

Hi,

Thank you for the code and the screenshots.

Could you please collect a [profiler capture](https://fmod.com/docs/2.02/studio/profiling.html) while reproducing this issue in the game, then [package your profiler session](https://fmod.com/docs/2.02/studio/profiling.html) including banks (ensure to tick the “Banks” option when exporting), and upload it to your [FMOD Profile](https://fmod.com/profile#uploads)? In the profiler recording, we will want to keep an eye on the event instance lifespans:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/9/9a1c30cfb1b563d1d46b44e4aad39d93f9295399.png)

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()](https://fmod.com/docs/2.02/api/studio-api-eventinstance.html#studio_eventinstance_isvalid) check:

```auto
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.
