Emitter Releasing OnDestroy()

Hello,

We’ve had a few problems with memory leaks lately and it seems to be coming from emitters stop trigger…. There are some emitters where we set the stop OnDestroy but they’re not being released properly, I’m debugging like this

`protected override void OnDestroy()
{
    if (!isQuitting)
    {
        HandleGameEvent(EmitterGameEvent.ObjectDestroy);

        if (instance.isValid())
        {
            RuntimeManager.DetachInstanceFromGameObject(instance);
            if (eventDescription.isValid() && isOneshot)
            {
                instance.release();
                instance.clearHandle();
            }
        }

        DeregisterActiveEmitter(this);

        if (Preload)
        {
            eventDescription.unloadSampleData();
        }
    }


    if (IsActive) {
        Debug.LogWarning($"IsQuitting: {isQuitting}. Active Emitter: {gameObject.name}. StopTrigger: {EventStopTrigger}.");
    }
}`

We’re also not reloading the domain when entering play mode which could be causing instance to stay around too but that doesn’t explain why some emitters which are marked to Stop on destroy aren’t being stopped

Thank you for your time!

Hi,

Thank you for bringing this to our attention.

Could I please grab your Unity and FMOD integration versions?

Thanks Connor!

We’re currently using 2.03.10 for both!

1 Like

Thanks for the info.

Unfortunately, I was not able to reproduce the issue. Would it be possible to create a test Unity project that replicates the issue and upload it to your profile?

How are you tracking the memory leaks? Is this happening in builds or in editor?

Hey Connor,

They’re happening in the editor and after a bit more debugging seem to be related to code trying to access the activeEmitters list after re-entering play mode…. this is happening with looping sources.

I think our understanding was if we mark an emitter to stop OnDestroy then it would be safely released no matter what but this is not happening. So more info, it seems to be happening on 3D events which are not one shots and we have StopEventsOutsideMaxDistance on too, as said before we’re not reloading the domain each time as this slows down dev time.

I’ve uploaded a OnDestroy Test project which should demonstrate what’s going on, if you enter play mode and exit, then re-enter, FMOD throws an error and no sound is played.

Some info on how to safely release emitters would be much appreciated, thanks so much Connor!

Thank you for the project. I have been able to reproduce the issue.

The missing link was the Reload Domain as that was allowing the activeEmitters list to hand around after relaunching PIE. A work around is removing the if (!isQuitting) check from the OnDestory() function in the StudioEventEmitters.cs. This will result in all Studio emitters stopping when their object is destroyed however. A task to address this issue has been made and will be included in an upcoming release.

Thank you for brining this to our attention.

1 Like