# \[BUG\] If stop is called twice, Unity shuts down without any error logs

**URL:** <https://qa.fmod.com/t/bug-if-stop-is-called-twice-unity-shuts-down-without-any-error-logs/22994>\
**Category:** Unity\
**Tags:** unity\
**Created:** [May 31, 2025, 5:47am UTC](https://qa.fmod.com/t/bug-if-stop-is-called-twice-unity-shuts-down-without-any-error-logs/22994 "2025-05-31T05:47:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![twocomet](https://avatars.discourse-cdn.com/v4/letter/t/ed8c4c/32.png) [@twocomet](https://qa.fmod.com/u/twocomet)\
**Post date:** [May 31, 2025, 5:47am UTC](https://qa.fmod.com/t/bug-if-stop-is-called-twice-unity-shuts-down-without-any-error-logs/22994/1 "2025-05-31T05:47:20Z")

</div>

```auto
static FMOD.RESULT FmodEventCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, IntPtr instancePtr, IntPtr parameterPtr)
{
switch (type)
{
    case FMOD.Studio.EVENT_CALLBACK_TYPE.SOUND_PLAYED:
        {
            FMOD.Studio.EventInstance instance = new FMOD.Studio.EventInstance(instancePtr);

            if (!instance.isValid())
                break;

            var result = instance.getPlaybackState(out var state);
            if (result == FMOD.RESULT.OK && state == FMOD.Studio.PLAYBACK_STATE.PLAYING)
            {
                instance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
            }
            break;
        }
}
}

```

In a specific situation where there were dozens of sound instances are playing, a looping music event was stopped externally, but some of the sounds would not stop no matter what. So, I tried checking in the callback and forcefully calling `stop`.

However, when using it this way, if `stop` is called twice, Unity forcefully crashes every time without any warning.

Please look into this.

The code shown above was just a simplified example.  
In the actual implementation, there are additional triggers involved.  
I’ve already tried safely ensuring that `stop` is called only once,  
but the music can still be heard in some cases.

So when I try to forcefully call `stop` one more time,  
Unity crashes immediately without fail.

Please investigate this issue.

```auto
case FMOD.Studio.EVENT_CALLBACK_TYPE.SOUND_PLAYED:
    {
        FMOD.Studio.EventInstance instance = new FMOD.Studio.EventInstance(instancePtr);

        if (!instance.isValid() || !fmodMap.ContainsKey(instance))
            break;

        if (!fmodMap[instance].loop && 
            !fmodMap[instance].isPlaying &&
            fmodMap[instance].IsStopTriggered(instance))
        {
            var result = instance.getPlaybackState(out var state);
            if (result == FMOD.RESULT.OK && state == FMOD.Studio.PLAYBACK_STATE.PLAYING)
            {
                instance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE/* AllowFadeout ? FMOD.Studio.STOP_MODE.ALLOWFADEOUT : FMOD.Studio.STOP_MODE.IMMEDIATE*/);
                fmodMap[instance].SetStopTrigger(instance, false);
            }
        } 

        break;
    }

```

The music is still audible, and when I check the state, it is  
`state == FMOD.Studio.PLAYBACK_STATE.PLAYING`.

If I then try to call `stop`, Unity crashes immediately.  
Why does calling `stop` more than once cause Unity to shut down?

Please review the internal FMOD code to ensure that repeated `stop` calls during playback do not crash Unity.  
If a sound is still playing, the `stop` function should safely handle the call and exit gracefully, not crash the application.

A crash like this proves that the FMOD core is entering an invalid or unstable state.

state == FMOD.Studio.PLAYBACK\_STATE.PLAYING

If there is a safer and more reliable function to forcefully stop a sound, please let me know.  
I have confirmed through multiple state checks that the instance is in the `SOUND_PLAYED` state, yet when I call `stop`, Unity crashes.

Despite verifying that all status functions indicate it is clearly in the `PLAYING` state, calling `stop` still causes Unity to terminate.

If there’s a lower-level or more robust method to guarantee a sound is stopped without causing instability, I would appreciate it if you could point it out.

---

<div class="post-metadata">

**Author:** ![twocomet](https://avatars.discourse-cdn.com/v4/letter/t/ed8c4c/32.png) [@twocomet](https://qa.fmod.com/u/twocomet)\
**Post date:** [May 31, 2025, 6:19am UTC](https://qa.fmod.com/t/bug-if-stop-is-called-twice-unity-shuts-down-without-any-error-logs/22994/2 "2025-05-31T06:19:29Z")

</div>

I am adding some additional information I confirmed.

In the case of the `SOUND_PLAYED` instance:

```auto
FMOD.Studio.EventInstance instance = new FMOD.Studio.EventInstance(instancePtr);

```

At this point, `instancePtr` has the pointer address `0x345000`.

`instance.isValid()` returns `true`, and the playback state is `PLAYBACK_STATE.PLAYING`.

The `stop` function has already been called once,  
but the state remains in “play”, the debug shows `real = 1`, and the sound is still playing.

Additionally, if I run the `stop` function again after several seconds,  
Unity crashes immediately and forcibly shuts down.

If I skip the `stop()` call and instead run:

```auto
instance.release();
instance.clearHandle();

```

then `instance.isValid()` immediately returns `false`.

However, when the next callback message comes in,  
`instancePtr` is still `0x345000`, `instance.isValid()` is `true`, and it remains in the playing state.  
The sound never actually stops!

This sound is being played in 3D with looping enabled.

Is there _really_ no way for me to stop this sound?

---

<div class="post-metadata">

**Author:** ![twocomet](https://avatars.discourse-cdn.com/v4/letter/t/ed8c4c/32.png) [@twocomet](https://qa.fmod.com/u/twocomet)\
**Post date:** [May 31, 2025, 6:21am UTC](https://qa.fmod.com/t/bug-if-stop-is-called-twice-unity-shuts-down-without-any-error-logs/22994/3 "2025-05-31T06:21:57Z")

</div>

The reason I’m pointing out this issue is because the loop sound that never stops continues to accumulate over time while the game is running.

If the number of these sounds exceeds the virtual channel limit, **no other sounds will play correctly**.  
This is expected behavior from FMOD’s perspective — because those loop sounds are still occupying channels — but it’s also a **critical issue** , effectively a bug.

Even after calling `stop()`, the sound continues playing.  
As I previously mentioned, calling `instance.release()` and `instance.clearHandle()` makes `isValid()` return `false`, but the callback still receives a valid `instancePtr` with `isValid() == true` and `PLAYBACK_STATE.PLAYING`.

**This looped 3D sound simply refuses to stop.**

Please provide a clear solution or workaround.  
As of now, the sound **still does not stop** , and it causes the system to run out of available channels over time.

---

<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:** [June 2, 2025, 3:52am UTC](https://qa.fmod.com/t/bug-if-stop-is-called-twice-unity-shuts-down-without-any-error-logs/22994/4 "2025-06-02T03:52:22Z")

</div>

Hi,

Thank you for all the information and the code.

Unfortunately, I was not able to reproduce the issue.

Are you able to create a stripped out Unity project and upload it to your [profile](https://fmod.com/profile#uploads)? The FMOD project with the following settings would be graet too:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/b/b11f9807e3891ae25a6214e7166a13d48b166c0f.png)  
Could I please grab your FMOD version:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/8/8c5fe38351dd756c24862cb02e6c8bda3008dcd8.png)  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/d/de09776734b7a68fb0cb28b49ff2f1799069b759.png)

Would it also be possible to add an `result` to the `instance.stop()` function to check it is not failing? If you enable the following:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/f/fa2275fd66b8cd09ab723dafcbf309470f610c03.png)  
And share the full logs:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/8/860e678da5b6934db93d447e89eb4ed73b359ee5.png)

If possible, a profiler session ([FMOD Studio | Profiler](https://fmod.com/docs/2.02/studio/profiling.html)) would be great too!
