Stuck on "Reloading domain" when the preferences are set to recompile after finished playing

Hi,

We recently installed the Hot Reload plugin for Unity (Download | Hot Reload for Unity) which made us change our preferences settings to “Recompile After Finished Playing”. The problem is that when we exit the play mode, Unity tries to recompile and fails to do it because of FMOD. The window “Reloading domain” can’t disappear and we have to kill Unity process. Here is the editor.log part that explain the problem :

Reloading assemblies after forced synchronous recompile.
Begin MonoManager ReloadAssembly
Thread 0x381d87000 may have been prematurely finalized
UnityException: Load can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
  at (wrapper managed-to-native) UnityEngine.ResourcesAPIInternal.Load(string,System.Type)
  at UnityEngine.ResourcesAPI.Load (System.String path, System.Type systemTypeInstance) [0x00000] in /Users/bokken/build/output/unity/unity/Runtime/Export/Resources/Resources.bindings.cs:71 
  at UnityEngine.Resources.Load (System.String path, System.Type systemTypeInstance) [0x00001] in /Users/bokken/build/output/unity/unity/Runtime/Export/Resources/Resources.bindings.cs:122 
  at UnityEngine.Resources.Load (System.String path) [0x00001] in /Users/bokken/build/output/unity/unity/Runtime/Export/Resources/Resources.bindings.cs:112 
  at FMODUnity.Settings.Initialize () [0x0001a] in /Users/francois/Projects/Arckhania/Assets/Plugins/FMOD/src/Settings.cs:267 
  at FMODUnity.Settings.get_Instance () [0x0000f] in /Users/francois/Projects/Arckhania/Assets/Plugins/FMOD/src/Settings.cs:255 
  at FMODUnity.RuntimeUtils.DebugLogError (System.String message) [0x00001] in /Users/francois/Projects/Arckhania/Assets/Plugins/FMOD/src/RuntimeUtils.cs:572 
  at FMODUnity.RuntimeManager.DEBUG_CALLBACK (FMOD.DEBUG_FLAGS flags, System.IntPtr filePtr, System.Int32 line, System.IntPtr funcPtr, System.IntPtr messagePtr) [0x00023] in /Users/francois/Projects/Arckhania/Assets/Plugins/FMOD/src/RuntimeManager.cs:77 
  at (wrapper native-to-managed) FMODUnity.RuntimeManager.DEBUG_CALLBACK(FMOD.DEBUG_FLAGS,intptr,int,intptr,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 /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/UnhandledExceptionHandler.bindings.cs:46)
UnityEngine.ResourcesAPIInternal:Load(String, Type)
UnityEngine.ResourcesAPI:Load(String, Type) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Resources/Resources.bindings.cs:71)
UnityEngine.Resources:Load(String, Type) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Resources/Resources.bindings.cs:122)
UnityEngine.Resources:Load(String) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Resources/Resources.bindings.cs:112)
FMODUnity.Settings:Initialize() (at Assets/Plugins/FMOD/src/Settings.cs:267)
FMODUnity.Settings:get_Instance() (at Assets/Plugins/FMOD/src/Settings.cs:255)
FMODUnity.RuntimeUtils:DebugLogError(String) (at Assets/Plugins/FMOD/src/RuntimeUtils.cs:572)
FMODUnity.RuntimeManager:DEBUG_CALLBACK(DEBUG_FLAGS, IntPtr, Int32, IntPtr, IntPtr) (at Assets/Plugins/FMOD/src/RuntimeManager.cs:77)

(Filename: Assets/Plugins/FMOD/src/Settings.cs Line: 267)

Notes :

  • Macbook Pro M1 Max 16"
  • Unity 2022.2.5f1 (silicon build)
  • FMOD 2.02.11 (tested with 2.02.09 too)

Hi,

Changing a reference and trying to trigger a OneShot I was not able to reproduce the issue.

Were there any particular changes you were making when it was getting stuck? Or is it every time you try and end play mode?

Would it be possible to get a stripped-out version of the Unity project that is experiencing the issue uploaded to your Profile?

It happens everytime I exit play mode. If I comment the line that is causing this problem in the Settings.cs , Fmod doesn’t work but the game can exit play mode properly. Did you try it with an Apple Silicon build ? Maybe it’s only related to this specific version, I don’t know.

It would be really hard for us to send the project right now.

Do you have an update on this ? We can try to build an empty repro project if needed.

Hi,

Apologies for the delayed response. That would be extremely useful, you can either upload the project to your Profile or DM me directly.

Same thing for us.

Unity 2023.1.19
FMOD 2.02.19

After exiting playmode we sometime get stuck on “reloading domain”.
Same error in Editor log as the post starter.

I have had to force quit Unity 5 times today.

Hi,

This can be caused if you interact with the Core FMOD system and objects aren’t being released correctly. Was there a recent change made that introduced the issue?

Hey,

I’m having the same issue where Unity gets stuck reloading scripts / domain.

In my code, I have an event with a beat callback. When I exit play mode, the music keeps playing and Unity freezes when I try and reload.
It looks like FMOD is throwing an Exception when trying to release the event due to the instance receiving the callback becoming null?

NullReferenceException: Object reference not set to an instance of an object
Surfside.UI.RadioController.HandleMusicBeat (FMOD.Studio.EVENT_CALLBACK_TYPE type, System.IntPtr eventInstance, System.IntPtr parameters) (at Assets/Scripts/UI/RadioController.cs:138)
FMOD.Studio.System.release () (at Assets/Plugins/FMOD/src/fmod_studio.cs:423)
FMODUnity.RuntimeManager.ReleaseStudioSystem () (at Assets/Plugins/FMOD/src/RuntimeManager.cs:266)
FMODUnity.RuntimeManager.OnDestroy () (at Assets/Plugins/FMOD/src/RuntimeManager.cs:723)

The line of code that is pointed to in the top of the stack trace is this:

if (type == EVENT_CALLBACK_TYPE.TIMELINE_BEAT && radioImage != null)

I do not get this issue when I don’t call setCallBack() on my EventInstance. Calling release() on it in OnDestroy doesn’t seem to help either.

I’m on Uinty 2022.3.12 & FMOD 2.02.21

Edit: When the game starts, I create an event instance, set the callback, and play. When I exit play mode, I call stop and release on the event instance.

Hi,
Would it be possible to see more of the code? What operating system are you on? Could I get a screenshot of the event in your FMOD project?

1 Like

Hey, yeah! Yesterday I was in the office on my Mac, and the issue was as described. Trying it out at home on my Windows desktop, the music continues for a short time after exiting play mode and then Unity actually just crashes.

private void Start()
{
    var eventDesc = RuntimeManager.GetEventDescription(eventReference.Guid);
    var instance = eventDesc.createInstance(out EventInstance newInstance);
    beatCallback = new EVENT_CALLBACK(HandleMusicBeat);
    instance.setCallback(beatCallback, EVENT_CALLBACK_TYPE.TIMELINE_BEAT);

    instance.start();
}

private void OnDestroy()
{
    currentMusicInstsance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
    currentMusicInstsance.release();
}

private RESULT HandleMusicBeat(EVENT_CALLBACK_TYPE type, IntPtr eventInstance, IntPtr parameters)
 {
        if (type == EVENT_CALLBACK_TYPE.TIMELINE_BEAT && radioImage != null)
        {
            radioImage.transform.DOPunchScale(new Vector3(0.05f, 0.05f, 0), 0.2f, 10, 0).SetUpdate(true);  
        }
        return RESULT.OK;
}

Edit:
Here’s the stacktrace the crash gave me:

=================================================================
	Managed Stacktrace:
=================================================================
	  at <unknown> <0xffffffff>
	  at FMOD.Studio.System:FMOD_Studio_System_Release <0x00089>
	  at FMOD.Studio.System:release <0x00022>
	  at FMODUnity.RuntimeManager:ReleaseStudioSystem <0x0005a>
	  at FMODUnity.RuntimeManager:OnDestroy <0x00042>
	  at System.Object:runtime_invoke_void__this__ <0x00087>
	  at <unknown> <0xffffffff>
	  at UnityEngine.Object:DestroyImmediate <0x00094>
	  at UnityEngine.Object:DestroyImmediate <0x00022>
	  at FMODUnity.RuntimeManager:Destroy <0x0005a>
	  at FMODUnity.RuntimeManager:HandlePlayModeStateChange <0x0007a>
	  at UnityEditor.EditorApplication:Internal_PlayModeStateChanged <0x000aa>
	  at <Module>:runtime_invoke_void_int <0x0008a>
=================================================================

Thank you for the code.

We have a scripting example outlining creating a BeatEventCallback here: Unity Integration | Scripting Examples - Timeline Callbacks. Would it be possible to compare against this as it may provide a solution?

Hope this helps

1 Like

Thank you for sending this example! I must have missed in in my searching.

I have solved the crash issue on my Windows machine by making the HandleMusicBeat callback method static. The method signature is as follows: private static RESULT HandleMusicBeat(EVENT_CALLBACK_TYPE type, IntPtr eventInstance, IntPtr parameters)

I assume the issue is also solved on Mac, but I won’t be in the office for a few days so I won’t know till then.

1 Like