From 16d1b358e6bcd257bc681d614848267837f84857 Mon Sep 17 00:00:00 2001 From: sahvx655-wq Date: Sun, 21 Jun 2026 01:00:41 +0530 Subject: [PATCH] clamp angular weight span before narrowing to int --- Source/astcenc_weight_align.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Source/astcenc_weight_align.cpp b/Source/astcenc_weight_align.cpp index 249fbf8d..e53494cc 100644 --- a/Source/astcenc_weight_align.cpp +++ b/Source/astcenc_weight_align.cpp @@ -225,8 +225,13 @@ static void compute_lowest_and_highest_weight( cut_high_weight_err = select(cut_high_weight_err, accum, mask); } - // Write out min weight and weight span; clamp span to a usable range - vint span = float_to_int(maxidx - minidx + vfloat(1)); + // Write out min weight and weight span; clamp span to a usable range. + // The span is derived from the ideal weights, which are non-finite when + // the input texels are non-finite, so clamp into the representable result + // range before narrowing to avoid an out-of-range float to int conversion + vfloat spanf = clamp(0.0f, static_cast(max_quant_steps + 3), + maxidx - minidx + vfloat(1)); + vint span = float_to_int(spanf); span = min(span, vint(max_quant_steps + 3)); span = max(span, vint(2)); storea(minidx, lowest_weight + sp);