diff --git a/Robust.Shared/Audio/AudioParams.cs b/Robust.Shared/Audio/AudioParams.cs index fa7557dec..426691abc 100644 --- a/Robust.Shared/Audio/AudioParams.cs +++ b/Robust.Shared/Audio/AudioParams.cs @@ -5,6 +5,9 @@ using Robust.Shared.Audio.Systems; using Robust.Shared.Serialization.Manager; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Log; +using Robust.Shared.Utility; namespace Robust.Shared.Audio { @@ -29,11 +32,25 @@ namespace Robust.Shared.Audio [DataDefinition] public partial struct AudioParams { + private float _volume = Default.Volume; + /// /// Base volume to play the audio at, in dB. /// [DataField] - public float Volume { get; set; } = Default.Volume; + public float Volume + { + get => _volume; + set + { + if (float.IsNaN(value)) + { + value = float.NegativeInfinity; + } + + _volume = value; + } + } /// /// Scale for the audio pitch. diff --git a/Robust.Shared/Audio/Systems/SharedAudioSystem.cs b/Robust.Shared/Audio/Systems/SharedAudioSystem.cs index 14e51c7ee..936831c6c 100644 --- a/Robust.Shared/Audio/Systems/SharedAudioSystem.cs +++ b/Robust.Shared/Audio/Systems/SharedAudioSystem.cs @@ -412,6 +412,13 @@ public abstract partial class SharedAudioSystem : EntitySystem if (component.Params.Volume.Equals(value)) return; + // Not a log error for now because if something has a negative infinity volume (i.e. 0 gain) then subtracting from it can + // easily cause this and making callers deal with it everywhere is quite annoying. + if (float.IsNaN(value)) + { + value = float.NegativeInfinity; + } + component.Params.Volume = value; component.Volume = value; DirtyField(entity.Value, component, nameof(AudioComponent.Params));