Skip to content

Commit

Permalink
Fixed out of memory for big topscreen splashes.
Browse files Browse the repository at this point in the history
  • Loading branch information
profi200 committed Jan 14, 2019
1 parent c81ca41 commit 7cce7bf
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion include/arm11/menu/splash.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ typedef struct


void getSplashDimensions(const void *const data, u32 *const width, u32 *const height);
bool drawSplashscreen(const void *const data, s32 startX, s32 startY, u8 screen);
bool drawSplashscreen(const void *const data, u16 *const tmpBuf, s32 startX, s32 startY, u8 screen);
17 changes: 14 additions & 3 deletions source/arm11/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,20 @@ int main(void)
}
else
{
splash_wait = drawSplashscreen(banner_spla, -1, -1, SCREEN_TOP);
if (bootmode == BootModeQuick)
drawSplashscreen(menu_spla, -1, 16, SCREEN_SUB);
u16 *const tmpBuf = malloc(SCREEN_WIDTH_TOP * SCREEN_HEIGHT_TOP * 2);
if(tmpBuf)
{
splash_wait = drawSplashscreen(banner_spla, tmpBuf, -1, -1, SCREEN_TOP);
if (bootmode == BootModeQuick)
drawSplashscreen(menu_spla, tmpBuf, -1, 16, SCREEN_SUB);
free(tmpBuf);
}
else
{
err_string = (char*) malloc(512);
if(!err_string) panicMsg("Out of memory");
ee_sprintf(err_string, "Internal splash screen error\n");
}
}
updateScreens();
}
Expand Down
12 changes: 7 additions & 5 deletions source/arm11/menu/menu_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ bool drawCustomSplash(const char* folder)
// this assumes top and bottom screens cleared
const u32 splash_max_size = sizeof(SplashHeader) + (SCREEN_WIDTH_TOP * SCREEN_HEIGHT_TOP * 2);
char* splash_path = (char*) malloc(FF_MAX_LFN + 1);
u8* splash_buffer = (u8*) malloc(splash_max_size);
u8* splash_buffer = (u8*) malloc(splash_max_size + (30 * 1024));
bool res = false;
s32 fHandle;

Expand All @@ -248,15 +248,16 @@ bool drawCustomSplash(const char* folder)
if (fHandle >= 0)
{
u32 splash_size = fSize(fHandle);
u16 *const splash_data = (u16*)(splash_buffer + splash_max_size + (30 * 1024) - splash_size);
if ((splash_size < sizeof(SplashHeader)) || (splash_size > splash_max_size) ||
(fRead(fHandle, splash_buffer, splash_size) != FR_OK))
(fRead(fHandle, splash_data, splash_size) != FR_OK))
{
fClose(fHandle);
goto fail;
}
fClose(fHandle);

if (drawSplashscreen(splash_buffer, -1, -1, SCREEN_TOP))
if (drawSplashscreen(splash_data, (u16*)splash_buffer, -1, -1, SCREEN_TOP))
res = true;
}

Expand All @@ -266,15 +267,16 @@ bool drawCustomSplash(const char* folder)
if (fHandle >= 0)
{
u32 splash_size = fSize(fHandle);
u16 *const splash_data = (u16*)(splash_buffer + splash_max_size + (30 * 1024) - splash_size);
if ((splash_size < sizeof(SplashHeader)) || (splash_size > splash_max_size) ||
(fRead(fHandle, splash_buffer, splash_size) != FR_OK))
(fRead(fHandle, splash_data, splash_size) != FR_OK))
{
fClose(fHandle);
goto fail;
}
fClose(fHandle);

if (drawSplashscreen(splash_buffer, -1, -1, SCREEN_SUB))
if (drawSplashscreen(splash_data, (u16*)splash_buffer, -1, -1, SCREEN_SUB))
res = true;
}

Expand Down
9 changes: 4 additions & 5 deletions source/arm11/menu/splash.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ static bool validateSplashHeader(const SplashHeader *const header, u8 screen)
return true;
}

bool drawSplashscreen(const void *const data, s32 startX, s32 startY, u8 screen)
bool drawSplashscreen(const void *const data, u16 *const tmpBuf, s32 startX, s32 startY, u8 screen)
{
if(!data || !tmpBuf) return false;

const SplashHeader *const header = (const SplashHeader *const)data;
if(!validateSplashHeader(header, screen)) return false;

Expand All @@ -62,8 +64,7 @@ bool drawSplashscreen(const void *const data, s32 startX, s32 startY, u8 screen)
u16 *imgData;
if(isCompressed)
{
imgData = (u16*)malloc(width * height * 2);
if(!imgData) return false;
imgData = tmpBuf;
lz11Decompress(data + sizeof(SplashHeader), imgData, width * height * 2);
}
else imgData = (u16*)(data + sizeof(SplashHeader));
Expand Down Expand Up @@ -93,7 +94,5 @@ bool drawSplashscreen(const void *const data, s32 startX, s32 startY, u8 screen)
}
}

if(isCompressed) free(imgData);

return true;
}

0 comments on commit 7cce7bf

Please sign in to comment.