From abaa6c6dd91ef58c3ed77b537f614e69397fbe7e Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Fri, 9 Dec 2022 14:48:53 +1300 Subject: [PATCH] Increase error tolerance of power debug assert (#12828) --- Content.Server/Power/Pow3r/BatteryRampPegSolver.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Content.Server/Power/Pow3r/BatteryRampPegSolver.cs b/Content.Server/Power/Pow3r/BatteryRampPegSolver.cs index c7195e918a..54e52ef435 100644 --- a/Content.Server/Power/Pow3r/BatteryRampPegSolver.cs +++ b/Content.Server/Power/Pow3r/BatteryRampPegSolver.cs @@ -252,7 +252,14 @@ namespace Content.Server.Power.Pow3r // available supply. IMO this is undesirable, but I can't think of an easy fix ATM. battery.CurrentStorage -= frameTime * battery.CurrentSupply; - DebugTools.Assert(battery.CurrentStorage >= 0 || MathHelper.CloseTo(battery.CurrentStorage, 0, 1e-5)); +#if DEBUG + // Manual "MathHelper.CloseToPercent" using the subtracted value to define the relative error. + if (battery.CurrentStorage < 0) + { + float epsilon = Math.Max(frameTime * battery.CurrentSupply, 1) * 1e-4f; + DebugTools.Assert(battery.CurrentStorage > -epsilon); + } +#endif battery.CurrentStorage = MathF.Max(0, battery.CurrentStorage); battery.SupplyRampTarget = battery.MaxEffectiveSupply * relativeTargetBatteryOutput - battery.CurrentReceiving * battery.Efficiency;