fix preview logic to prevent old previews showing if none is found in the newly selected entry

This commit is contained in:
LiquidFenrir
2017-12-07 16:46:53 +01:00
parent 7c3ca57e07
commit c1ef601c2f

View File

@@ -28,6 +28,7 @@
#include "pp2d/pp2d/pp2d.h" #include "pp2d/pp2d/pp2d.h"
#include "fs.h" #include "fs.h"
#include "unicode.h" #include "unicode.h"
#include "draw.h"
u32 load_data(char * filename, Entry_s entry, char ** buf) u32 load_data(char * filename, Entry_s entry, char ** buf)
{ {
@@ -153,10 +154,6 @@ bool load_preview(Entry_List_s list, int * preview_offset)
Entry_s entry = list.entries[list.selected_entry]; Entry_s entry = list.entries[list.selected_entry];
if(!memcmp(&previous_path, &entry.path, 0x106*sizeof(u16))) return true; if(!memcmp(&previous_path, &entry.path, 0x106*sizeof(u16))) return true;
else 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);
char *preview_buffer = NULL; char *preview_buffer = NULL;
u64 size = load_data("/preview.png", entry, &preview_buffer); u64 size = load_data("/preview.png", entry, &preview_buffer);
@@ -164,9 +161,14 @@ bool load_preview(Entry_List_s list, int * preview_offset)
if(!size) if(!size)
{ {
free(preview_buffer); free(preview_buffer);
throw_error("No preview found.", ERROR_LEVEL_WARNING);
return false; 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; bool ret = false;
u8 * image = NULL; u8 * image = NULL;
unsigned int width = 0, height = 0; unsigned int width = 0, height = 0;