From cfc8eb93ba13a18390c66ce254a02f5bff5310ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Sun, 1 Jun 2025 22:48:13 -0400 Subject: [PATCH] Fix libretro save state serialization of `Bitmap.fill_rect` --- src/display/bitmap.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/display/bitmap.cpp b/src/display/bitmap.cpp index f3b5b41b..bfaa9a41 100644 --- a/src/display/bitmap.cpp +++ b/src/display/bitmap.cpp @@ -1788,16 +1788,17 @@ void Bitmap::fillRect(Exception &exception, const IntRect &rect, const Vec4 &col p->fillRect(rect, color); #ifdef MKXPZ_RETRO - uint8_t *pixels = (uint8_t *)STBI_MALLOC(4 * rect.w * rect.h); + uint32_t *pixels = (uint32_t *)STBI_MALLOC(4 * rect.w * rect.h); if (pixels == nullptr) MKXPZ_THROW(std::bad_alloc()); + const uint8_t pixel[4] = { + (uint8_t)clamp(color.x * 255.0f, 0.0f, 255.0f), + (uint8_t)clamp(color.y * 255.0f, 0.0f, 255.0f), + (uint8_t)clamp(color.z * 255.0f, 0.0f, 255.0f), + (uint8_t)clamp(color.w * 255.0f, 0.0f, 255.0f), + }; for (size_t i = 0; i < rect.w * rect.h; ++i) - { - pixels[4 * i] = color.x; - pixels[4 * i + 1] = color.y; - pixels[4 * i + 2] = color.z; - pixels[4 * i + 3] = color.w; - } + std::memcpy(pixels + i, pixel, 4); p->pushDiff(pixels, rect); stbi_image_free(pixels); #endif // MKXPZ_RETRO