FMOD instance errors fix

This commit is contained in:
Timur Nizamov
2026-01-30 21:01:11 +02:00
parent 52701f3231
commit 5a13928a59
4 changed files with 37 additions and 15 deletions

View File

@@ -291,6 +291,11 @@ public class AudioManager : MonoBehaviour
} }
public static void Pause()
{
musicEventInstance.setPaused(true);
}
//=====// //=====//
//=====// //=====//
@@ -323,6 +328,8 @@ public class AudioManager : MonoBehaviour
// Set the callback for programmer sounds // Set the callback for programmer sounds
instance.setCallback(dialogueCallback); instance.setCallback(dialogueCallback);
bool managedByOcclusion = false;
// Add occlusion if available on the emitter // Add occlusion if available on the emitter
if (emitter != null) if (emitter != null)
{ {
@@ -330,11 +337,16 @@ public class AudioManager : MonoBehaviour
if (occlusion != null) if (occlusion != null)
{ {
occlusion.InitialiseWithInstance(instance); occlusion.InitialiseWithInstance(instance);
managedByOcclusion = true;
} }
} }
instance.start(); instance.start();
instance.release();
if (!managedByOcclusion)
{
instance.release();
}
} }
@@ -414,11 +426,6 @@ public class AudioManager : MonoBehaviour
instance.setPaused(false); instance.setPaused(false);
} }
public static void Pause()
{
musicEventInstance.setPaused(true);
}
public static void Pause(EventInstance instance) public static void Pause(EventInstance instance)
{ {
instance.setPaused(true); instance.setPaused(true);
@@ -430,8 +437,10 @@ public class AudioManager : MonoBehaviour
{ {
foreach (EventInstance eventInstance in eventInstances) foreach (EventInstance eventInstance in eventInstances)
{ {
eventInstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE); if (eventInstance.isValid()) {
eventInstance.release(); eventInstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
eventInstance.release();
}
} }
} }

View File

@@ -75,7 +75,7 @@ public class FirstPersonOcclusion : MonoBehaviour
AudioOccluded.start(); AudioOccluded.start();
// 4. Releasing Instance (This allows the event to self-manage its lifetime, which is fine) // 4. Releasing Instance (This allows the event to self-manage its lifetime, which is fine)
AudioOccluded.release(); //AudioOccluded.release();
managedInstances.Add(AudioOccluded); // ADDED managedInstances.Add(AudioOccluded); // ADDED
@@ -205,4 +205,17 @@ public class FirstPersonOcclusion : MonoBehaviour
} }
} }
} }
private void OnDestroy()
{
// Stop & release all instances when this object is destroyed
foreach (var inst in managedInstances)
{
if (inst.isValid())
{
inst.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
inst.release();
}
}
managedInstances.Clear();
}
} }

View File

@@ -8,6 +8,10 @@
"name": "timur", "name": "timur",
"score": 486.0 "score": 486.0
}, },
{
"name": "taavi",
"score": 480.0
},
{ {
"name": "ppppVBBPPP", "name": "ppppVBBPPP",
"score": 478.0 "score": 478.0
@@ -55,10 +59,6 @@
{ {
"name": "yty", "name": "yty",
"score": 446.0 "score": 446.0
},
{
"name": "lp",
"score": 444.0
} }
] ]
} }