From 9929c35021bfc6c1bec1b677c85f6d732b7e01d6 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sat, 31 May 2025 15:43:50 +0200 Subject: [PATCH] Correctly format single digit hex values --- CHANGELOG.md | 1 + components/misc/color.cpp | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4117e86054..fa0c43be25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -235,6 +235,7 @@ Bug #8462: Crashes when resizing the window on macOS Bug #8465: Blue screen w/ antialiasing and post-processing on macOS Bug #8503: Camera does not handle NaN gracefully + Bug #8541: Lua: util.color:asHex produces wrong output for some colors Feature #1415: Infinite fall failsafe Feature #2566: Handle NAM9 records for manual cell references Feature #3501: OpenMW-CS: Instance Editing - Shortcuts for axial locking diff --git a/components/misc/color.cpp b/components/misc/color.cpp index 5b0278570a..b6e7be1fa3 100644 --- a/components/misc/color.cpp +++ b/components/misc/color.cpp @@ -47,7 +47,10 @@ namespace Misc for (size_t i = 0; i < rgb.size(); i++) { int b = static_cast(rgb[i] * 255.0f); - auto [_, ec] = std::to_chars(result.data() + i * 2, result.data() + (i + 1) * 2, b, 16); + char* start = result.data() + i * 2; + if (b < 16) + start++; + auto [_, ec] = std::to_chars(start, result.data() + (i + 1) * 2, b, 16); if (ec != std::errc()) throw std::logic_error("Error when converting number to base 16"); }