Skip to content

Commit

Permalink
fix: FMOD master channel group spam (#459)
Browse files Browse the repository at this point in the history
Fixed FMOD channel lock spams
  • Loading branch information
Metious committed Sep 13, 2023
1 parent 2534880 commit 612ccb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions Nautilus/Handlers/CustomSoundHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public static Sound RegisterCustomSound(string id, string filePath, string busPa
/// <returns>the <see cref="Sound"/> loaded</returns>
public static Sound RegisterCustomSound(string id, string filePath, Bus bus, MODE mode = MODE.DEFAULT)
{
if (bus.getChannelGroup(out _) != RESULT.OK)
if (bus.getChannelGroup(out ChannelGroup channelGroup) != RESULT.OK || !channelGroup.hasHandle())
{
bus.lockChannelGroup().CheckResult();
bus.lockChannelGroup();
}
Sound sound = AudioUtils.CreateSound(filePath, mode);
CustomSoundPatcher.CustomSounds[id] = sound;
Expand Down Expand Up @@ -75,9 +75,9 @@ public static Sound RegisterCustomSound(string id, AudioClip audio, string busPa
/// <returns>the <see cref="Sound"/> loaded</returns>
public static Sound RegisterCustomSound(string id, AudioClip audio, Bus bus, MODE mode = MODE.DEFAULT)
{
if (bus.getChannelGroup(out _) != RESULT.OK)
if (bus.getChannelGroup(out ChannelGroup channelGroup) != RESULT.OK || !channelGroup.hasHandle())
{
bus.lockChannelGroup().CheckResult();
bus.lockChannelGroup();
}
Sound sound = AudioUtils.CreateSound(audio, mode);
CustomSoundPatcher.CustomSounds[id] = sound;
Expand Down Expand Up @@ -115,9 +115,9 @@ public static void RegisterCustomSound(string id, Sound sound, string busPath)
/// <param name="bus">The bus to play the sound on.</param>
public static void RegisterCustomSound(string id, Sound sound, Bus bus)
{
if (bus.getChannelGroup(out _) != RESULT.OK)
if (bus.getChannelGroup(out ChannelGroup channelGroup) != RESULT.OK || !channelGroup.hasHandle())
{
bus.lockChannelGroup().CheckResult();
bus.lockChannelGroup();
}
CustomSoundPatcher.CustomSounds[id] = sound;
CustomSoundPatcher.CustomSoundBuses[id] = bus;
Expand Down
12 changes: 6 additions & 6 deletions Nautilus/Utility/AudioUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ public static bool TryPlaySound(Sound sound, string busPath, out Channel channel
{
channel = default;
Bus bus = RuntimeManager.GetBus(busPath);
if (bus.getChannelGroup(out _) != RESULT.OK)
if (bus.getChannelGroup(out ChannelGroup channelGroup) != RESULT.OK || !channelGroup.hasHandle())
{
bus.lockChannelGroup().CheckResult();
bus.lockChannelGroup();
}
return bus.getChannelGroup(out ChannelGroup channelGroup) == RESULT.OK &&
return bus.getChannelGroup(out channelGroup) == RESULT.OK &&
channelGroup.getPaused(out bool paused) == RESULT.OK &&
FMOD_System.playSound(sound, channelGroup, paused, out channel) == RESULT.OK;
}
Expand All @@ -104,11 +104,11 @@ public static bool TryPlaySound(Sound sound, string busPath, out Channel channel
public static bool TryPlaySound(Sound sound, Bus bus, out Channel channel)
{
channel = default;
if (bus.getChannelGroup(out _) != RESULT.OK)
if (bus.getChannelGroup(out ChannelGroup channelGroup) != RESULT.OK || !channelGroup.hasHandle())
{
bus.lockChannelGroup().CheckResult();
bus.lockChannelGroup();
}
return bus.getChannelGroup(out ChannelGroup channelGroup) == RESULT.OK &&
return bus.getChannelGroup(out channelGroup) == RESULT.OK &&
channelGroup.getPaused(out bool paused) == RESULT.OK &&
FMOD_System.playSound(sound, channelGroup, paused, out channel) == RESULT.OK;
}
Expand Down

0 comments on commit 612ccb4

Please sign in to comment.