From 10019cdabdf43622776678acab919dffd16bc879 Mon Sep 17 00:00:00 2001 From: Kevin Zheng Date: Wed, 16 Nov 2022 06:22:28 -0800 Subject: [PATCH] Fix debug crash due to probability being outside 0-1 (#12616) --- Content.Server/Botany/Systems/MutationSystem.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Content.Server/Botany/Systems/MutationSystem.cs b/Content.Server/Botany/Systems/MutationSystem.cs index d1cbd58d3d..186c2b6b08 100644 --- a/Content.Server/Botany/Systems/MutationSystem.cs +++ b/Content.Server/Botany/Systems/MutationSystem.cs @@ -112,8 +112,10 @@ public class MutationSystem : EntitySystem return; } - // Starting number of bits that are high, between 0 and n. + // Starting number of bits that are high, between 0 and bits. int n = (int)Math.Round((val - min) / (max - min) * bits); + // val may be outside the range of min/max due to starting prototype values, so clamp + n = Math.Clamp(n, 0, bits); // Probability that the bit flip increases n. float p_increase = 1-(float)n/bits;