Crash in Callback when Jumping to Another Marker in FMOD During a Transition

Hi,

We are experiencing a crash in Unity when trying to jump to another marker inside an FMOD event from a callback. Everything works fine until we reach the transition between two sections of the audio. At that moment, Unity crashes with an error.

Context
We have an event in FMOD Studio with markers (Loop1, Transition, etc.).

In the FMOD callback, we try to detect a marker and jump to another marker within the same event.

The crash occurs exactly during the transition between audio sections.

Unity throws a SIGSEGV error and references FMOD.Studio.System:update()

At the moment we are using this callback:

protected override void StartGame()
    {
        base.StartGame();
        
        currentEvent.start();
        currentEvent.setCallback(EventCallback, EVENT_CALLBACK_TYPE.TIMELINE_MARKER);
    }


private RESULT EventCallback(EVENT_CALLBACK_TYPE type, IntPtr eventInstance, IntPtr parameters)
    {
        if (type == EVENT_CALLBACK_TYPE.TIMELINE_MARKER)
        {
            var properties = (TIMELINE_MARKER_PROPERTIES)Marshal.PtrToStructure(parameters, typeof(TIMELINE_MARKER_PROPERTIES));
            string nameString = properties.name;

            if (nameString.StartsWith("Loop"))
            {
                loopTimer = 0;
                indexArrow = 0;
                loopMusicPlaying = true;
                
                ++currentLoopsPlayedInLevel;
        
                currentEvent.setParameterByName(NextLevelParameter, 
                    (currentLoopsPlayedInLevel >= MaxLoopsPlayedPerLevel && currentLevel < NumLevels - 1) ? 1 : 0);
                
                if (currentLoopsPlayedInLevel == MaxLoopsPlayedPerLevel)
                {
                    currentEvent.setParameterByName(TransNextLevelParameter, currentLevel + 1);
                }
            }
            else if (nameString.StartsWith("Transition"))
            {
                if (currentLoopsPlayedInLevel >= MaxLoopsPlayedPerLevel && currentLevel < NumLevels - 1)
                {
                    currentLevel += 1;
                    currentLoopsPlayedInLevel = 0;
                }
                
                var indexLoopToPlay = new Random().Next(1, LoopsPerLevel);
                currentEvent.setParameterByName(LoopParameter, 1);
                currentEvent.setParameterByName(LevelParameter, currentLevel + 1); 
                currentLoopArrowsData = infiniteModeData[currentLevel].LoopsData[indexLoopToPlay].ArrowsData;
            }
        }
        return RESULT.OK;
    }

The Unity crash log is the following:

=================================================================
	Native Crash Reporting
=================================================================
Got a UNKNOWN while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

=================================================================
	Managed Stacktrace:
=================================================================
	  at <unknown> <0xffffffff>
	  at FMOD.Studio.System:FMOD_Studio_System_Update <0x000e3>
	  at FMOD.Studio.System:update <0x0008a>
	  at FMODUnity.RuntimeManager:Update <0x02382>
	  at System.Object:runtime_invoke_void__this__ <0x00187>
=================================================================
Received signal SIGSEGV
Obtained 2 stack frames
RtlLookupFunctionEntry returned NULL function. Aborting stack walk.
<Missing stacktrace information>

Thanks in advance.

Hi,

Thank you for the screenshots and the code.

The issue is you are missing the annotation: [AOT.MonoPInvokeCallback(typeof(FMOD.Studio.EVENT_CALLBACK))] above the function and we need to make sure the callback function is static:

[AOT.MonoPInvokeCallback(typeof(FMOD.Studio.EVENT_CALLBACK))]
static FMOD.RESULT BeatEventCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, IntPtr instancePtr, IntPtr parameterPtr)

We have en example timeline marker callback script here: Unity Integration | Scripting Examples - Timeline Callbacks.

Hope this helps!

1 Like