mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Fix NaN gain audio (#5737)
This commit is contained in:
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Base volume to play the audio at, in dB.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public float Volume { get; set; } = Default.Volume;
|
||||
public float Volume
|
||||
{
|
||||
get => _volume;
|
||||
set
|
||||
{
|
||||
if (float.IsNaN(value))
|
||||
{
|
||||
value = float.NegativeInfinity;
|
||||
}
|
||||
|
||||
_volume = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scale for the audio pitch.
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user