From 310c92bee2017bf76f9c874ce17c3ebc5a999179 Mon Sep 17 00:00:00 2001 From: LiquidFenrir Date: Fri, 15 Dec 2017 20:37:29 +0100 Subject: [PATCH] only mark preview as loaded if the png parsing actually worked, and add a warning (#112) --- source/loading.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/source/loading.c b/source/loading.c index 801f676..d3873fb 100644 --- a/source/loading.c +++ b/source/loading.c @@ -174,10 +174,6 @@ bool load_preview(Entry_List_s list, int * preview_offset) return false; } - // free the previously loaded preview. wont do anything if there wasnt one - pp2d_free_texture(TEXTURE_PREVIEW); - memcpy(&previous_path, &entry.path, 0x106*sizeof(u16)); - bool ret = false; u8 * image = NULL; unsigned int width = 0, height = 0; @@ -193,10 +189,20 @@ bool load_preview(Entry_List_s list, int * preview_offset) } } + // mark the new preview as loaded for optimisation + memcpy(&previous_path, &entry.path, 0x106*sizeof(u16)); + // free the previously loaded preview. wont do anything if there wasnt one + pp2d_free_texture(TEXTURE_PREVIEW); + pp2d_load_texture_memory(TEXTURE_PREVIEW, image, (u32)width, (u32)height); + *preview_offset = (width-400)/2; ret = true; } + else + { + throw_error("Corrupted/invalid preview.png", ERROR_LEVEL_WARNING); + } free(image); free(preview_buffer);