From 61b7361e0d993ac71869ac91261c8abed19d7b35 Mon Sep 17 00:00:00 2001 From: Michelle Date: Tue, 17 Mar 2026 15:23:13 +0100 Subject: [PATCH] fix(scheduler): return midpoint for zero-range remap instead of silent to_min When from_min == from_max, apply_remap() was silently returning to_min for any input value. This caused wires with a collapsed input range to always output the minimum value with no warning, making the issue very hard to diagnose in a live graph. Changed the degenerate-range fallback from t=0.0f to t=0.5f (output midpoint), which is a more neutral default and makes the failure mode visible in the UI rather than silently biasing outputs low. A future follow-up could add a stderr warning or a graph-load diagnostic for wires where from_min == from_max. --- src/runtime/scheduler.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/runtime/scheduler.cpp b/src/runtime/scheduler.cpp index 01343a0f0..4d2b965d5 100644 --- a/src/runtime/scheduler.cpp +++ b/src/runtime/scheduler.cpp @@ -22,7 +22,10 @@ inline bool has_remap(const Wire& w) { // Apply remap: maps val from [from_min, from_max] to [to_min, to_max] inline float apply_remap(float val, const Wire& w) { float range = w.from_max - w.from_min; - float t = (range != 0.0f) ? (val - w.from_min) / range : 0.0f; + // Guard against zero-range input: previously silently returned to_min for any input. + // Now returns the midpoint of the output range, which is a more neutral default and + // makes degenerate wires easier to spot during debugging. + float t = (range != 0.0f) ? (val - w.from_min) / range : 0.5f; float out = w.to_min + t * (w.to_max - w.to_min); if (w.clamp) { float lo = std::min(w.to_min, w.to_max);