[Linux] FMOD logging in Unity causes stack overflow

When I run my relatively heavy scene Unity crashes at runtime. Looking at the logs it seems to come from some kind of recursive logging loop in FMOD which causes a stack overflow.
I tried changing the log level to None or Error and then it doesn’t happen. on Warning it happens at some point at runtime (usually like 10 seconds in), and on Log it just crashes on launch.


context

I’m running

  • FMOD Unity and studio 2.03.12 (it also happens on 2.03.06)
  • Unity: 6000.3.2f1
  • OS: NixOS 25.11 (Linux kernel 6.18.1).

Also in Unity we’re working with Unity Entities which has required some workarounds to be able to use FMOD which could be a problem but so far hasn’t triggered this.

I’ve been working on this project for a while now and only recently this has become an issue. So the only direction I have is that there are just more calls happening at once, there’s no specific implementation I made that causes it with the testing I’ve done so far (which has only been on Linux right now).


Is this a known issue? I couldn’t find anything about it apart from this post some years back


Here’s the relevant part of the editor log:

(Filename: Assets/Plugins/FMOD/src/RuntimeUtils.cs Line: 564)

[FMOD] Thread::initThread : Init FMOD mixer thread. Affinity: 0x4000000000000001, Priority: 0xFFFF7FFA, Stack Size: 81920, Semaphore: No, Sleep Time: 0, Looping: Yes.
UnityEngine.Debug:ExtractStackTraceNoAlloc (byte*,int,string)
UnityEngine.StackTraceUtility:ExtractStackTrace () (at /home/bokken/build/output/unity/unity/Runtime/Export/Scripting/StackTrace.cs:35)
UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
UnityEngine.Logger:Log (UnityEngine.LogType,object)
UnityEngine.Debug:Log (object)
FMODUnity.RuntimeUtils:DebugLog (string) (at Assets/Plugins/FMOD/src/RuntimeUtils.cs:564)
FMODUnity.RuntimeManager:DEBUG_CALLBACK (FMOD.DEBUG_FLAGS,intptr,int,intptr,intptr) (at Assets/Plugins/FMOD/src/RuntimeManager.cs:112)
FMOD.Studio.System:initialize (int,FMOD.Studio.INITFLAGS,FMOD.INITFLAGS,intptr) (at Assets/Plugins/FMOD/src/fmod_studio.cs:419)
FMODUnity.RuntimeManager:Initialize () (at Assets/Plugins/FMOD/src/RuntimeManager.cs:381)
FMODUnity.RuntimeManager:get_Instance () (at Assets/Plugins/FMOD/src/RuntimeManager.cs:212)
FMODUnity.RuntimeManager:HasBankLoaded (string) (at Assets/Plugins/FMOD/src/RuntimeManager.cs:1534)
Audio.MonoBehaviours.FMODAudioManager:InitializeBanksBlocking (Audio.Utils.AudioBank[]) (at Assets/Scripts/Audio/MonoBehaviours/FMODAudioManager.cs:40)
Audio.MonoBehaviours.FMODAudioManager:Awake () (at Assets/Scripts/Audio/MonoBehaviours/FMODAudioManager.cs:25)

(Filename: Assets/Plugins/FMOD/src/RuntimeUtils.cs Line: 564)

StackOverflowException: The requested operation caused a stack overflow.
  at UnityEngine.StackTraceUtility.ExtractStackTrace () [0x00007] in /home/bokken/build/output/unity/unity/Runtime/Export/Scripting/StackTrace.cs:33 
  at (wrapper managed-to-native) UnityEngine.DebugLogHandler.Internal_Log_Injected(UnityEngine.LogType,UnityEngine.LogOption,UnityEngine.Bindings.ManagedSpanWrapper&,intptr)
  at UnityEngine.DebugLogHandler.Internal_Log (UnityEngine.LogType level, UnityEngine.LogOption options, System.String msg, UnityEngine.Object obj) [0x00034] in <47cff71b0b7749a79b626569f499a43b>:0 
  at UnityEngine.DebugLogHandler.LogFormat (UnityEngine.LogType logType, UnityEngine.Object context, System.String format, System.Object[] args) [0x00001] in /home/bokken/build/output/unity/unity/Runtime/Export/Logging/DebugLogHandler.cs:9 
  at UnityEngine.Logger.Log (UnityEngine.LogType logType, System.Object message) [0x0000c] in /home/bokken/build/output/unity/unity/Runtime/Export/Logging/Logger.cs:60 
  at UnityEngine.Debug.Log (System.Object message) [0x00001] in /home/bokken/build/output/unity/unity/Runtime/Export/Debug/Debug.bindings.cs:123 
  at FMODUnity.RuntimeUtils.DebugLog (System.String message) [0x00014] in /home/subnite/dev/unity/Project-Name/Assets/Plugins/FMOD/src/RuntimeUtils.cs:564 
  at FMODUnity.RuntimeManager.DEBUG_CALLBACK (FMOD.DEBUG_FLAGS flags, System.IntPtr filePtr, System.Int32 line, System.IntPtr funcPtr, System.IntPtr messagePtr) [0x00066] in /home/subnite/dev/unity/Project-Name/Assets/Plugins/FMOD/src/RuntimeManager.cs:112 
  at (wrapper native-to-managed) FMODUnity.RuntimeManager.DEBUG_CALLBACK(FMOD.DEBUG_FLAGS,intptr,int,intptr,intptr)
UnityEngine.DebugLogHandler:Internal_LogException_Injected(Exception, IntPtr)
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.<>c:<RegisterUECatcher>b__0_0(Object, UnhandledExceptionEventArgs) (at /home/bokken/build/output/unity/unity/Runtime/Export/Scripting/UnhandledExceptionHandler.bindings.cs:46)
UnityEngine.DebugLogHandler:Internal_Log_Injected(LogType, LogOption, ManagedSpanWrapper&, IntPtr)
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
FMODUnity.RuntimeUtils:DebugLog(String) (at Assets/Plugins/FMOD/src/RuntimeUtils.cs:564)
FMODUnity.RuntimeManager:DEBUG_CALLBACK(DEBUG_FLAGS, IntPtr, Int32, IntPtr, IntPtr) (at Assets/Plugins/FMOD/src/RuntimeManager.cs:112)

(Filename: Assets/Plugins/FMOD/src/RuntimeUtils.cs Line: 564)

StackOverflowException: The requested operation caused a stack overflow.
  at Unity.PlasticSCM.Editor.PlasticApp.HandleUnhandledException (System.Object sender, System.UnhandledExceptionEventArgs args) [0x0004e] in ./Library/PackageCache/com.unity.collab-proxy@3351acaba9c9/Editor/PlasticApp.cs:257 
  at (wrapper delegate-invoke) <Module>.invoke_void_object_UnhandledExceptionEventArgs(object,System.UnhandledExceptionEventArgs)
  at (wrapper managed-to-native) UnityEngine.DebugLogHandler.Internal_Log_Injected(UnityEngine.LogType,UnityEngine.LogOption,UnityEngine.Bindings.ManagedSpanWrapper&,intptr)
  at UnityEngine.DebugLogHandler.Internal_Log (UnityEngine.LogType level, UnityEngine.LogOption options, System.String msg, UnityEngine.Object obj) [0x00034] in <47cff71b0b7749a79b626569f499a43b>:0 
  at UnityEngine.DebugLogHandler.LogFormat (UnityEngine.LogType logType, UnityEngine.Object context, System.String format, System.Object[] args) [0x00001] in /home/bokken/build/output/unity/unity/Runtime/Export/Logging/DebugLogHandler.cs:9 
  at UnityEngine.Logger.Log (UnityEngine.LogType logType, System.Object message) [0x0000c] in /home/bokken/build/output/unity/unity/Runtime/Export/Logging/Logger.cs:60 
  at UnityEngine.Debug.Log (System.Object message) [0x00001] in /home/bokken/build/output/unity/unity/Runtime/Export/Debug/Debug.bindings.cs:123 
  at FMODUnity.RuntimeUtils.DebugLog (System.String message) [0x00014] in /home/subnite/dev/unity/Project-Name/Assets/Plugins/FMOD/src/RuntimeUtils.cs:564 
  at FMODUnity.RuntimeManager.DEBUG_CALLBACK (FMOD.DEBUG_FLAGS flags, System.IntPtr filePtr, System.Int32 line, System.IntPtr funcPtr, System.IntPtr messagePtr) [0x00066] in /home/subnite/dev/unity/Project-Name/Assets/Plugins/FMOD/src/RuntimeManager.cs:112 
  at (wrapper native-to-managed) FMODUnity.RuntimeManager.DEBUG_CALLBACK(FMOD.DEBUG_FLAGS,intptr,int,intptr,intptr)
UnityEngine.DebugLogHandler:Internal_LogException_Injected(Exception, IntPtr)
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.<>c:<RegisterUECatcher>b__0_0(Object, UnhandledExceptionEventArgs) (at /home/bokken/build/output/unity/unity/Runtime/Export/Scripting/UnhandledExceptionHandler.bindings.cs:46)
UnityEngine.DebugLogHandler:Internal_Log_Injected(LogType, LogOption, ManagedSpanWrapper&, IntPtr)
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
FMODUnity.RuntimeUtils:DebugLog(String) (at Assets/Plugins/FMOD/src/RuntimeUtils.cs:564)
FMODUnity.RuntimeManager:DEBUG_CALLBACK(DEBUG_FLAGS, IntPtr, Int32, IntPtr, IntPtr) (at Assets/Plugins/FMOD/src/RuntimeManager.cs:112)

(Filename: Assets/Plugins/FMOD/src/RuntimeUtils.cs Line: 564)

Stack overflow: IP: 0x7f8bf3a77da0, fault addr: 0x7f8cc4677bb8
Stacktrace:
  at <unknown> <0xffffffff>
  at System.Text.StringBuilder.ExpandByABlock (int) [0x00080] in <1a795a29c7af4385b159eb69f68237b8>:0
  <...>
  at System.Text.StringBuilder.Append (char*,int) [0x000a5] in <1a795a29c7af4385b159eb69f68237b8>:0
  at System.Text.StringBuilder.AppendHelper (string) [0x00018] in <1a795a29c7af4385b159eb69f68237b8>:0
  at System.Text.StringBuilder.Append (string) [0x00085] in <1a795a29c7af4385b159eb69f68237b8>:0
  at System.Text.StringBuilder.AppendFormatHelper (System.IFormatProvider,string,System.ParamsArray) [0x003b5] in <1a795a29c7af4385b159eb69f68237b8>:0
  at System.Text.StringBuilder.AppendFormat (string,object,object) [0x0000a] in <1a795a29c7af4385b159eb69f68237b8>:0
  at System.Diagnostics.StackTrace.AddFrames (System.Text.StringBuilder,bool,bool&) [0x0017a] in <1a795a29c7af4385b159eb69f68237b8>:0
  at System.Diagnostics.StackTrace.ToString () [0x00062] in <1a795a29c7af4385b159eb69f68237b8>:0
  at System.Diagnostics.StackTrace.ToString (System.Diagnostics.StackTrace/TraceFormat) [0x00001] in <1a795a29c7af4385b159eb69f68237b8>:0
  at System.Environment.GetStackTrace (System.Exception,bool) [0x00016] in <1a795a29c7af4385b159eb69f68237b8>:0
  at System.Exception.GetStackTrace (bool) [0x0003a] in <1a795a29c7af4385b159eb69f68237b8>:0
  at System.Exception.get_StackTrace () [0x00002] in <1a795a29c7af4385b159eb69f68237b8>:0
  at UnityEngine.StackTraceUtility.ExtractStringFromExceptionInternal (object,string&,string&) [0x00032] in /home/bokken/build/output/unity/unity/Runtime/Export/Scripting/StackTrace.cs:62
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object_intptr&_intptr& (object,intptr,intptr,intptr) [0x00037] in <47cff71b0b7749a79b626569f499a43b>:0
  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) UnityEngine.DebugLogHandler.Internal_LogException_Injected (System.Exception,intptr) [0x00008] in <47cff71b0b7749a79b626569f499a43b>:0
  at UnityEngine.DebugLogHandler.Internal_LogException (System.Exception,UnityEngine.Object) [0x00007] in <47cff71b0b7749a79b626569f499a43b>:0
  at UnityEngine.DebugLogHandler.LogException (System.Exception,UnityEngine.Object) [0x00014] in /home/bokken/build/output/unity/unity/Runtime/Export/Logging/DebugLogHandler.cs:22
  at UnityEngine.Logger.LogException (System.Exception,UnityEngine.Object) [0x0000b] in /home/bokken/build/output/unity/unity/Runtime/Export/Logging/Logger.cs:132
  at UnityEngine.Debug.LogException (System.Exception) [0x00001] in /home/bokken/build/output/unity/unity/Runtime/Export/Debug/Debug.bindings.cs:202
  at UnityEngine.UnhandledExceptionHandler/<>c.<RegisterUECatcher>b__0_0 (object,System.UnhandledExceptionEventArgs) [0x00001] in /home/bokken/build/output/unity/unity/Runtime/Export/Scripting/UnhandledExceptionHandler.bindings.cs:46
  at (wrapper delegate-invoke) <Module>.invoke_void_object_UnhandledExceptionEventArgs (object,System.UnhandledExceptionEventArgs) [0x00077] in <1a795a29c7af4385b159eb69f68237b8>:0
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object_object (object,intptr,intptr,intptr) [0x00033] in <1a795a29c7af4385b159eb69f68237b8>:0
  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) UnityEngine.DebugLogHandler.Internal_Log_Injected (UnityEngine.LogType,UnityEngine.LogOption,UnityEngine.Bindings.ManagedSpanWrapper&,intptr) [0x0000a] in <47cff71b0b7749a79b626569f499a43b>:0
  at UnityEngine.DebugLogHandler.Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object) [0x00034] in <47cff71b0b7749a79b626569f499a43b>:0
  at UnityEngine.DebugLogHandler.LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[]) [0x00001] in /home/bokken/build/output/unity/unity/Runtime/Export/Logging/DebugLogHandler.cs:9
  at UnityEngine.Logger.Log (UnityEngine.LogType,object) [0x0000c] in /home/bokken/build/output/unity/unity/Runtime/Export/Logging/Logger.cs:60
  at UnityEngine.Debug.Log (object) [0x00001] in /home/bokken/build/output/unity/unity/Runtime/Export/Debug/Debug.bindings.cs:123
  at FMODUnity.RuntimeUtils.DebugLog (string) [0x00014] in /home/subnite/dev/unity/Project-Name/Assets/Plugins/FMOD/src/RuntimeUtils.cs:564
  at FMODUnity.RuntimeManager.DEBUG_CALLBACK (FMOD.DEBUG_FLAGS,intptr,int,intptr,intptr) [0x00066] in /home/subnite/dev/unity/Project-Name/Assets/Plugins/FMOD/src/RuntimeManager.cs:112
  at (wrapper native-to-managed) FMODUnity.RuntimeManager.DEBUG_CALLBACK (FMOD.DEBUG_FLAGS,intptr,int,intptr,intptr) [0x00038] in <b7f95691d6b740cda873af658ad7df61>:0
e[40me[32minfoe[39me[22me[49m: Microsoft.Hosting.Lifetime[0]
      Application is shutting down...
e[40me[32minfoe[39me[22me[49m: Unity.ILPP.Runner.PostProcessingAssemblyLoadContext[0]
      ALC ILPP context 1 is unloading

Hi,

Thanks for bringing this to our attention. Would it be possible to share a stripped out version of the project that is displaying the issue? I am not able to reproduce the issue in a test scene on my side.

Thank you for sharing the workaround.

Hi Connor.

Sorry but I cannot really strip the project down to reproduce the bug since we don’t have that kind of time currently.
The best I can do is give you this project which contains our usage of FMOD with Unity Entities and a quick rundown of how we’re handling things. It does reproduce the bug albeit only with Logging set to Log, since I’m not triggering warnings I think?


Quick Rundown

Entities uses the Burst compiler and general DOTS implementation for its speed. We’re working with tons of instances for example so this technology is really needed.

Anyways, in Burst we cannot use managed object types so the default RuntimeManager for FMOD doesn’t cut it. The workaround here is to:

  1. Bake a singleton at runtime which holds a hash map that links an enum (for the fmod audio event) with an EventDescription (which is Burst compatible since it’s blittable)
  2. Create EventInstances from that EventDescription since they are also blittable and work with those.

Because EventDescriptions, and EventInstances are basically just a pointer, most of the functions on that pointer still work in Jobs and Burst compiled contexts. (Some don’t because they require strings for example which are managed.)


Project

I’m sorry if the project has some spaghetti code, I didn’t have much time to make it pretty.

For me currently it works if I set the FMOD Setting logging to None, and if I set it to Log this causes the crash.

Essentially in the sample scene I just have a bunch of entities that play sounds based on a timer. This is apparently enough to trigger some kind of log in FMOD which crashes Unity.

Layout

Entity systems are in Assets/Scripts/Systems, Assets/Scripts/Authoring holds the components that get baked to Entities, and then there are some utility functions / wrappers that mimic the way our project handles FMOD in Assets/Scripts/Utils.

I’m building the audio banks to Assets/StreamingAssets/AudioBanks as multi platform banks.

Apart from that, all Entities have to be in the entity subscene of the sample scene. I think the rest is pretty self explanatory.


If you need any further information or help I’d be happy to answer of course.

And I do realize this is probably the only resource on the internet currently that explains how to use FMOD with Unity Entities / DOTS, so if anyone wants a more detailed and prettier post I can do that at some point. I’ve been meaning to since it was such a pain to both learn entities and make FMOD work with it.

There’s a lot more to know about how to link event instances to entities and make them follow positions, using parameters in jobs, and linking event instances to lifetimes of entity objects, …

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

I have created a task to investigate the issue further.

Thank you for sharing your workaround and information about using FMOD with DOTS and burst. I will also make another task to see if we can add some docs about these as well.