From 12ec05879e4cf5e0d83f9f82471775bfeccc88eb Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 15 May 2025 21:12:39 +1000 Subject: [PATCH] Fix resized to power of two skin initialising the unused area with garbage, which could be seen with custom models --- src/Entity.c | 4 +++- src/LBackend.c | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Entity.c b/src/Entity.c index 082ac1687..69b0a3ce7 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -301,7 +301,9 @@ static cc_result EnsurePow2Skin(struct Entity* e, struct Bitmap* bmp) { height = Math_NextPowOf2(bmp->height); if (width == bmp->width && height == bmp->height) return 0; - Bitmap_TryAllocate(&scaled, width, height); + scaled.width = width; + scaled.height = height; + scaled.scan0 = (BitmapCol*)Mem_TryAllocCleared(width * height, BITMAPCOLOR_SIZE); if (!scaled.scan0) return ERR_OUT_OF_MEMORY; e->uScale = (float)bmp->width / width; diff --git a/src/LBackend.c b/src/LBackend.c index 295ee28c0..02f1cb390 100644 --- a/src/LBackend.c +++ b/src/LBackend.c @@ -115,7 +115,10 @@ static void LBackend_ScaleFlag(struct Bitmap* bmp) { /* at default DPI don't need to rescale it */ if (width == bmp->width && height == bmp->height) return; - Bitmap_TryAllocate(&scaled, width, height); + scaled.width = width; + scaled.height = height; + scaled.scan0 = (BitmapCol*)Mem_TryAlloc(width * height, BITMAPCOLOR_SIZE); + if (!scaled.scan0) { Logger_SysWarn(ERR_OUT_OF_MEMORY, "resizing flags bitmap"); return; }