From 9461bb5a6537dd54a34cce904f4601031ae1b4ed Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 2 Mar 2020 21:35:20 +1100 Subject: [PATCH] Don't crash if out of memory resizing flags bitmaps in launcher --- src/Entity.c | 2 +- src/LWeb.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Entity.c b/src/Entity.c index 30df163fb..b816f5e71 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -422,7 +422,7 @@ static cc_result Entity_EnsurePow2(struct Entity* e, Bitmap* bmp) { height = Math_NextPowOf2(bmp->Height); if (width == bmp->Width && height == bmp->Height) return 0; - Bitmap_Allocate(&scaled, width, height); + Bitmap_TryAllocate(&scaled, width, height); if (!scaled.Scan0) return ERR_OUT_OF_MEMORY; e->uScale = (float)bmp->Width / width; diff --git a/src/LWeb.c b/src/LWeb.c index 439d43ac2..b82a3892d 100644 --- a/src/LWeb.c +++ b/src/LWeb.c @@ -6,6 +6,7 @@ #include "Window.h" #include "Options.h" #include "PackedCol.h" +#include "Errors.h" #ifndef CC_BUILD_WEB /*########################################################################################################################* @@ -560,9 +561,12 @@ static void FetchFlagsTask_Scale(Bitmap* bmp) { /* at default DPI don't need to rescale it */ if (width == bmp->Width && height == bmp->Height) return; - Bitmap_Allocate(&scaled, width, height); - Bitmap_Scale(&scaled, bmp, 0, 0, bmp->Width, bmp->Height); + Bitmap_TryAllocate(&scaled, width, height); + if (!scaled.Scan0) { + Logger_Warn(ERR_OUT_OF_MEMORY, "resizing flags bitmap"); return; + } + Bitmap_Scale(&scaled, bmp, 0, 0, bmp->Width, bmp->Height); Mem_Free(bmp->Scan0); *bmp = scaled; }