Don't crash if out of memory resizing flags bitmaps in launcher

This commit is contained in:
UnknownShadow200 2020-03-02 21:35:20 +11:00
parent ddba7b8778
commit 9461bb5a65
2 changed files with 7 additions and 3 deletions

View File

@ -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;

View File

@ -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;
}