From 12bcd0ef8cf818af0f6070e056d9880f53909322 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 07:38:50 -0700 Subject: [PATCH] fix(brush): defensive guards in EditorBrush::getInfluence Three issues: 1. NaN distance returned 1.0 (full influence) because distance >= radius is false for NaN; the inner-radius check then returned 1. 2. Non-positive radius would divide by zero in the t computation. 3. falloff = 0 produces division by zero in the outer falloff path. Also clamps falloff to [0,1] so a slider extreme can't break the math. --- tools/editor/editor_brush.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/editor/editor_brush.cpp b/tools/editor/editor_brush.cpp index 43414778..f5bf651a 100644 --- a/tools/editor/editor_brush.cpp +++ b/tools/editor/editor_brush.cpp @@ -6,13 +6,20 @@ namespace wowee { namespace editor { float EditorBrush::getInfluence(float distance) const { + // NaN distance must produce 0 influence — comparisons against NaN + // return false, so without this the function would fall through to + // the "fully inside" branch and return 1.0 for every queried point. + if (!std::isfinite(distance) || !std::isfinite(settings_.radius) || + settings_.radius <= 0.0f) return 0.0f; if (distance >= settings_.radius) return 0.0f; float t = distance / settings_.radius; - float innerRadius = 1.0f - settings_.falloff; + float falloff = std::clamp(settings_.falloff, 0.0f, 1.0f); + float innerRadius = 1.0f - falloff; if (t <= innerRadius) return 1.0f; + if (falloff <= 0.0f) return 1.0f; // hard edge - float falloffT = (t - innerRadius) / settings_.falloff; + float falloffT = (t - innerRadius) / falloff; return 1.0f - (falloffT * falloffT); }