[FMOD] assert : assertion 'realInstance' Failed

Hello, This is my first asking question for FMOD. My team recently stumbled upon a bug on our game prototype which mute the audio and keep displaying this error :

“[FMOD] assert: assertion “RealInstance” failed”.

it occurs 30 minutes or so during the test, at the beginning of a new level generally. sometimes, it display :

“[FMOD] assert: assertion isEmpty() failed”.

and

“”[FMOD] assert: assertion ‘count==0’ failed".

after that, the sound is played normally until the level is finished, and mute afterwards.

Is someone have already encounter this kind of problem ? Does this come from FMOD 2.00.06 ?

Thank you for your answer !

This message indicates something has gone wrong while attempting to interact with an event instance, although it is not specific enough to know exactly what failed. Are you able to share the entire logs at all?

sorry for the delay in response. here’s the warning we had.

    [FMOD] EventInstance::update : Event {8e726a2e-8a1f-41ad-9766-7a4cc5275a05} waited 159 milliseconds for sample data to load.  Preload sample data to avoid this delay.

UnityEngine.Debug:LogWarning(Object)
FMODUnity.RuntimeManager:DEBUG_CALLBACK(DEBUG_FLAGS, StringWrapper, Int32, StringWrapper, StringWrapper) (at Assets/Plugins/FMOD/src/Runtime/RuntimeManager.cs:32)

we have this delay, but mostly we have growing command buffer size, which probably mean that we have a memorydump of some sort.

[FMOD] AsyncCommandBuffer::growBuffer : Growing command buffer to 65536 bytes. Initial command buffer size can be tuned to avoid dynamic growth using Studio::System::setAdvancedSettings()

UnityEngine.Debug:LogWarning(Object)
FMODUnity.RuntimeManager:DEBUG_CALLBACK(DEBUG_FLAGS, StringWrapper, Int32, StringWrapper, StringWrapper) (at Assets/Plugins/FMOD/src/Runtime/RuntimeManager.cs:32)
FMOD.Studio.EventInstance:FMOD_Studio_EventInstance_SetParameterByName(IntPtr, Byte[], Single, Boolean)
FMOD.Studio.EventInstance:setParameterByName(String, Single, Boolean) (at Assets/Plugins/FMOD/src/Runtime/wrapper/fmod_studio.cs:1242)
soundFmod:SetParameter(EventInstance, String, Single) (at Assets/Plugins/FMOD/src/Runtime/soundFmod.cs:117)
soundFmod:CheckType(Boolean, sound, EmitterGameEvents, Boolean, param, Int32, String[]) (at Assets/Plugins/FMOD/src/Runtime/soundFmod.cs:229)
soundFmod:PlaySound(EmitterGameEvents, String[]) (at Assets/Plugins/FMOD/src/Runtime/soundFmod.cs:140)
soundFmod:Start() (at Assets/Plugins/FMOD/src/Runtime/soundFmod.cs:46)

we also have a DSPjob list expanding

FMOD] DSPJobList::addJob : DSP JobList expanding job from 1024 entries to 2048 entries.

UnityEngine.Debug:LogWarning(Object)
FMODUnity.RuntimeManager:DEBUG_CALLBACK(DEBUG_FLAGS, StringWrapper, Int32, StringWrapper, StringWrapper) (at Assets/Plugins/FMOD/src/Runtime/RuntimeManager.cs:32)

_

This last two commands keeps getting bigger until it seems to not be able to.

at this point i have assuming that the problem was due to asychronous buffer data not be expunged and instances not been released.

I have use resetbufferusage() and release every instance, but i keep having the same problem. Should i make another question ? Is ther a way to reinitilize the buffer ?

As it says, the sample data for this event has not been preloaded which means FMOD has to load it at creation and will not be able to play it until it has been loaded, this can cause delays in playback.

It sounds like FMOD’s update is not being called and the commands are piling up.
Does that sound possible?
Are you manipulating the RuntimeManager or it’s systems at all?
Are you creating your own FMOD systems?

For’ each event of our script we create an instance and we setup with “RuntimeManager.AttachInstanceToGameObject”, we use “setParameterByName” and then instance.start().

Blockquote It sounds like FMOD’s update is not being called and the commands are piling up.
Does that sound possible?

it seems that updating and resetting the buffer usage don’t change anything. in my case, i log the current usage of the buffer. the buffer commandqueue is reset with resetBufferUsage, but not the studioHandle which seems to pile up.

here’s the code we use for the FMod

[HideInInspector]
public int focus;
public bool showDebug = true;

public List<sound> soundslist;

public int typeSol;

// ajout de compteur d'instance;
public int countInstance;

private void Awake()
{
    focus = 0;
    if (!GetComponent<Rigidbody>())
    {
        gameObject.AddComponent<Rigidbody>();
    }

    GetComponent<Rigidbody>().useGravity = false;
    foreach (var item in soundslist)
    {
        InitSound(item, true);
    }
}

void InitSound(sound item, bool firstInstance)
{
    if (firstInstance)
    {
        countInstance++;
        //Debug.Log(countInstance);
        FMOD.Studio.EventInstance instance = RuntimeManager.CreateInstance(item.Event);
        item.instance = instance;
    }
    item.instance.set3DAttributes(RuntimeUtils.To3DAttributes(gameObject));
    item.instance.setProperty(FMOD.Studio.EVENT_PROPERTY.MINIMUM_DISTANCE, item.minDist);
    item.instance.setProperty(FMOD.Studio.EVENT_PROPERTY.MAXIMUM_DISTANCE, item.MaxDist);
    RuntimeManager.AttachInstanceToGameObject(item.instance, GetComponent<Transform>(), GetComponent<Rigidbody>());
}

private void Start()
{
    PlaySound(sound.EmitterGameEvents.ObjectStart);
}

private void Update()
{
    foreach (var item in soundslist)
    {
        if (item.timerStart!= 0 && item.timerStart > Time.timeSinceLevelLoad)
        {
            item.instance.setVolume(0);
        }
        else if (item.timerStart != 0 && item.timerStart < Time.timeSinceLevelLoad)
        {
            item.instance.setVolume(1);
        }
    }
}

public void SetSoundVolume(int soundIndex, float volume)
{
    soundslist[soundIndex].instance.setVolume(volume);
}

private void OnTriggerEnter(Collider other)
{
    string[] nameTag = new string[2];
    nameTag[0] = other.tag;
    nameTag[1] = other.name;
    PlaySound(sound.EmitterGameEvents.TriggerEnter, nameTag);
}

public void CallCustomVoid(string nameVoid)
{
    string[] nameTag = new string[1];
    nameTag[0] = nameVoid;
    PlaySound(sound.EmitterGameEvents.customVoid, nameTag);
}

public void ChangeParam(string voidName, float valueToChange)
{
    foreach (var item in soundslist)
    {
        if (item.allParameters.Count > 0)
        {
            foreach (var param in item.allParameters)
            {
                for (int i = 0; i < param.triggerParam.Count; i++)
                {
                    if (param.triggerParam[i] == sound.EmitterGameEvents.customVoid)
                    {
                        if (param.tagNameCol[i] == voidName)
                        {
                            SetParameter(item.instance, param.paramName, valueToChange);
                        }
                    }
                }
            }
        }
    }
}

private void OnTriggerExit(Collider other)
{
    string[] nameTag = new string[2];
    nameTag[0] = other.tag;
    nameTag[1] = other.name;
    PlaySound(sound.EmitterGameEvents.TriggerExit, nameTag);
}

public void SetParameter(FMOD.Studio.EventInstance e, string name, float value)
{
    e.setParameterByName(name, value);
    if(name == "type_sol")
    {
        typeSol = (int)value;
    }
}

void PlaySound(sound.EmitterGameEvents type, params string[] nameOrTag)
{
    foreach (var item in soundslist)
    {
        /*if(item.instance.isValid() == false)
        {
            Debug.Log("passageinitsound");
            //InitSound(item, true);
        }*/
        if(item.allParameters.Count > 0)
        {
            foreach (var param in item.allParameters)
            {
                for (int i = 0; i < param.triggerParam.Count; i++)
                {
                    if (param.triggerParam[i] == type)
                    {
                        CheckType(true, item, param.triggerParam[i], false, param, i, nameOrTag);
                    }
                }
            }
        }
        if(!string.IsNullOrEmpty(item.Event))
        {
            for (int i = 0; i < item.triggerEvent.Count; i++)
            {
                if (item.triggerEvent[i] == type)
                {
                    CheckType(false, item, item.triggerEvent[i], false, null, i, nameOrTag);
                }
            }
            if (item.stopTriggerEvent.Count > 0)
            {
                for (int i = 0; i < item.stopTriggerEvent.Count; i++)
                {
                    if (item.stop[i])
                    {
                        if (item.stopTriggerEvent[i] == type)
                        {
                            CheckType(false, item, item.stopTriggerEvent[i], true, null, i, nameOrTag);
                        }
                    }
                }
            }
        }
    }
}

/// <summary>
/// Switch pour determiner le type de trigger
/// </summary>
/// <param name="isParam">S'il s'agit d'un param (true) ou un event (false)</param>
/// <param name="item">Item pour acceder a son instance</param>
/// <param name="type">Le type du trigger, valable pour parametre ou event</param>
/// <param name="param">Si isParam true alors renseigner le param a modifie</param>
/// <param name="index">L'index du paramTrigger pour avoir la value associée</param>
/// <param name="nameOrTag">Si type trigger alors le nom ou tag de l objet</param>
void CheckType(bool isParam, sound item, sound.EmitterGameEvents type, bool stop = false, sound.param param = null, int index = 0, params string[] nameOrTag)
{
    switch (type)
    {
        case sound.EmitterGameEvents.None:
            Debug.Log("None");
            return;
        case sound.EmitterGameEvents.customVoid:
            if (isParam)
            {
                if (param.tagNameCol[index] == nameOrTag[0])
                    SetParameter(item.instance, param.paramName, param.randomParam ? Random.Range(param.range[0], param.range[1]) : param.valueToChange[index]);
            }
            else
            {
                if (!stop)
                {
                    if (item.tagName[index] == nameOrTag[0])
                    {
                        InitSound(item, !item.instance.isValid());
                        if(item.allParameters.Count>0)
                        {
                            if (item.allParameters[0]?.paramName == "type_sol")
                            {
                                SetParameter(item.instance, "type_sol", (float)typeSol);
                            }
                        }
                        item.instance.start();

                        if(item.releaseEvent)
                        {
                            item.instance.clearHandle();
                            // ajout
                            //Debug.Log("destroy");
                            item.instance.release();
                        }

                        item.instance.clearHandle();
                        // ajout
                        //Debug.Log("destroy");
                        item.instance.release();
                    }
                }
                else
                {
                    if (item.tagNameExit[index] == nameOrTag[0])
                    {
                        item.instance.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
                        //ajout
                        item.instance.release();
                    }
                }
            }
            break;
        case sound.EmitterGameEvents.ObjectStart:
            if(isParam)
            {
                SetParameter(item.instance, param.paramName, param.randomParam ? Random.Range(param.range[0], param.range[1]) : param.valueToChange[index]);
            }
            else
            {
                if(!stop)
                {
                    InitSound(item, false);
                    item.instance.start();
                    if (item.releaseEvent)
                    {
                        item.instance.clearHandle();
                    }
                }
                else
                {
                    item.instance.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
                }
            }
            break;
        case sound.EmitterGameEvents.TriggerEnter:
            if (isParam)
            {
                if(param.tagNameCol[index] == nameOrTag[0] || param.tagNameCol[index] == nameOrTag[1])
                    SetParameter(item.instance, param.paramName, param.randomParam ? Random.Range(param.range[0], param.range[1]) : param.valueToChange[index]);
            }
            else
            {
                if (!stop)
                {
                    if (item.tagName[index] == nameOrTag[0] || item.tagName[index] == nameOrTag[1])
                    {
                        InitSound(item, false);
                        if (item.allParameters.Count > 0)
                        {
                            item.instance.getParameterByName(item.allParameters[0].paramName, out float test);
                        }
                        item.instance.start();
                        if (item.releaseEvent)
                        {
                            item.instance.clearHandle();
                        }
                    }
                }
                else
                {
                    if (item.tagNameExit[index] == nameOrTag[0] || item.tagNameExit[index] == nameOrTag[1])
                    {
                        item.instance.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
                    }
                }
            }
            break;
        case sound.EmitterGameEvents.TriggerExit:
            if (isParam)
            {
                if (param.tagNameCol[index] == nameOrTag[0] || param.tagNameCol[index] == nameOrTag[1])
                    SetParameter(item.instance, param.paramName, param.randomParam ? Random.Range(param.range[0], param.range[1]) : param.valueToChange[index]);
            }
            else
            {
                if (!stop)
                {
                    if (item.tagName[index] == nameOrTag[0] || item.tagName[index] == nameOrTag[1])
                    {
                        InitSound(item, false);
                        item.instance.start();

                        if (item.releaseEvent)
                        {
                            item.instance.clearHandle();
                        }
                    }
                }
                else
                {
                    if (item.tagNameExit[index] == nameOrTag[0] || item.tagNameExit[index] == nameOrTag[1])
                    {
                        item.instance.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
                    }
                }
            }
            break;
    }
}

private void OnDrawGizmos()
{
    Gizmos.DrawIcon(transform.position, "FMOD/FMODEmitter.tiff", true);
    if (soundslist.Count > 0 && showDebug)
    {
        Gizmos.color = Color.white;
        if (soundslist[0] != null)
        {
            Gizmos.DrawWireSphere(transform.position, soundslist[0].minDist);
            Gizmos.DrawWireSphere(transform.position, soundslist[0].MaxDist);
        }
    }
}

void OnDestroy()
{
    if(soundslist.Count > 0)
    {
        foreach (var item in soundslist)
        {
            item.instance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
            //ajout
            //Debug.Log("destroy");
            item.instance.release();
        }
    }
}

[System.Serializable]
public class sound
{
    [Header("Path Event")]
    public string Event;

    public bool releaseEvent;

    public enum EmitterGameEvents
    {
        None,
        ObjectStart,
        TriggerEnter,
        TriggerExit,
        customVoid
    }

    public float timerStart;

    [Header("Type trigger start event")]
    public List<EmitterGameEvents> triggerEvent = new List<EmitterGameEvents>(1);
    public List<string> tagName = new List<string>(1);

    [Header("Type trigger stop event")]
    public List<bool> stop = new List<bool>();
    public List<EmitterGameEvents> stopTriggerEvent = new List<EmitterGameEvents>(1);
    public List<string> tagNameExit = new List<string>(1);

    public FMOD.Studio.EventInstance instance;

    [Header("Parameters event")]
    public List<param> allParameters = new List<param>();
    
    [Header("Event distance 3D sound")]
    public float minDist;
    public float MaxDist = 50f;

    [System.Serializable]
    public class param
    {
        public string paramName;
        public bool randomParam;
        public List<EmitterGameEvents> triggerParam = new List<EmitterGameEvents>(1);
        public List<string> tagNameCol = new List<string>(1);
        public List<int> valueToChange = new List<int>(1);
        [HideInInspector] public int[] range = new int[2];
    }
}

it’s not mine (i’m not the programmer for this script) so don’t worry about pointing out problems.

Unfortunately nothing stands out in the code you provided.
Have you tried using a newer version of FMOD 2.00 to see that may fix it? You mentioned that you are using 2.00.06 and we are up to 2.00.17 as of now (and also have newer major versions but those will require some work to upgrade to).