From 781a1e39f550e12d3650772974cacb6b300c2c2c Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Sun, 15 Dec 2024 01:07:46 +0900 Subject: [PATCH] fix UI crasher caused by negative (unexpected) colorspace vrgb components. The following code somehow results in negative r value component: ```C++ ColorSpaces::vec3 vrgb = ColorSpaces::hcy_to_rgb(vhcy); ``` ... while hcy_to_rgb() itself calculates `vec3` (`std::array`) as expected. Negative components then leads to runtime crash. Considering that the function might return negative values anyway, filter out those negative values here at SColorRGB constructor to sanitize inputs. --- plugins/editor/src/editor/ColorHelpers.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/editor/src/editor/ColorHelpers.cpp b/plugins/editor/src/editor/ColorHelpers.cpp index 5ce3314d..7ea1c7c2 100644 --- a/plugins/editor/src/editor/ColorHelpers.cpp +++ b/plugins/editor/src/editor/ColorHelpers.cpp @@ -19,9 +19,9 @@ SColorRGB::SColorRGB(const SColorHCY &hcy) { ColorSpaces::vec3 vhcy{{hcy.h, hcy.c, hcy.y}}; ColorSpaces::vec3 vrgb = ColorSpaces::hcy_to_rgb(vhcy); - r = vrgb[0]; - g = vrgb[1]; - b = vrgb[2]; + r = fmax(0.0f, vrgb[0]); + g = fmax(0.0f, vrgb[1]); + b = fmax(0.0f, vrgb[2]); a = hcy.a; }