# \[BUG\] Settings.Instance doesn't check its current thread before calling Resources.Load

**URL:** <https://qa.fmod.com/t/bug-settings-instance-doesnt-check-its-current-thread-before-calling-resources-load/20974>\
**Category:** Unity\
**Tags:** unity, csharp\
**Created:** [December 10, 2023, 6:54pm UTC](https://qa.fmod.com/t/bug-settings-instance-doesnt-check-its-current-thread-before-calling-resources-load/20974 "2023-12-10T18:54:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lgarczyn](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@lgarczyn](https://qa.fmod.com/u/lgarczyn)\
**Post date:** [December 10, 2023, 6:54pm UTC](https://qa.fmod.com/t/bug-settings-instance-doesnt-check-its-current-thread-before-calling-resources-load/20974/1 "2023-12-10T18:54:08Z")

</div>

I’ve had a few editor freezes when live-recompiling code, and when checking the source, it appeared that every freeze was caused by a fmod external call.

The last one was caused by a unity exception thrown on DEBUG\_CALLBACK

The stack was:

Resources.Load  
Initialize  
Settings.Instance  
DebugLogWarning  
DEBUG\_CALLBACK

(had to do it from memory since I didn’t copy the code)

Resources.Load cannot be called from the fmod callback thread. This could be fixed by just modifying Instance.Initialize to something like:

```auto
        internal static void Initialize()
        {
            if (instance == null)
            {
                isInitializing = true;

                instance = null;

                // TODO: create issue about this in fmod forum
                try
                {
                    instance = Resources.Load(SettingsAssetName) as Settings;
                }
                catch (Exception e)
                {
                    // This call will not recursively call Initialize() again since isInitializing is set to true.
                    RuntimeUtils.DebugLog($"[FMOD] Tried to init Settings instance from wrong thread: {e}");
                    isInitializing = false;
                    return;
                }

                if (instance == null)
                {
                    RuntimeUtils.DebugLog("[FMOD] Cannot find integration settings, creating default settings");
                    instance = CreateInstance<Settings>();
                    instance.name = "FMOD Studio Integration Settings";
                    instance.CurrentVersion = FMOD.VERSION.number;
                    instance.LastEventReferenceScanVersion = FMOD.VERSION.number;

#if UNITY_EDITOR
                    if (editorSettings != null)
                    {
                        editorSettings.CreateSettingsAsset(SettingsAssetName);
                    }
                    else
                    {
                        // editorSettings is populated via the static constructor of FMODUnity.EditorSettings when in the Unity editor.
                        RuntimeUtils.DebugLogError("[FMOD] Attempted to instantiate Settings before EditorSettings was populated. " +
                            "Ensure that Settings.Instance is not being called from an InitializeOnLoad method or class.");
                    }
#endif
                }

                isInitializing = false;
            }
        }

```

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [December 17, 2023, 10:41pm UTC](https://qa.fmod.com/t/bug-settings-instance-doesnt-check-its-current-thread-before-calling-resources-load/20974/2 "2023-12-17T22:41:53Z")

</div>

Thank you for reporting the issue and information.

I have added this as a task that we will look into for an upcoming release.
