Memory leak fix and camera multithreading safety improvement (#239)

* memory leak fix and attempt at optimizing space

* camera rework

try to use better locking algorithm (MRSW lock on wikipedia)

* add time print (toggleable) and stuff

remove old mixed qr thingss from main

* remove the dumb 3 bytes saving

* remove useless time measure code

* forgot to close the stop event handle

* fix memory leak when loading icon from smdh

* fix entry path on folders

optimization using memcpy cause it to have the "/info.smdh" when the entry is a folder. simply remove that with a memset to 0.

Co-authored-by: Alex Taber <astronautlevel2@users.noreply.github.com>
This commit is contained in:
Théo B
2020-12-22 04:31:38 +01:00
committed by GitHub
parent 1c2e562dd6
commit 95ff2dd3ba
6 changed files with 315 additions and 238 deletions

View File

@@ -83,6 +83,7 @@ C2D_Image * loadTextureIcon(Icon_s *icon)
void parse_smdh(Icon_s *icon, Entry_s * entry, const u16 * fallback_name)
{
/*
if(icon == NULL)
{
memcpy(entry->name, fallback_name, 0x80);
@@ -91,28 +92,13 @@ void parse_smdh(Icon_s *icon, Entry_s * entry, const u16 * fallback_name)
entry->placeholder_color = C2D_Color32(rand() % 255, rand() % 255, rand() % 255, 255);
return;
}
*/
memcpy(entry->name, icon->name, 0x40*sizeof(u16));
memcpy(entry->desc, icon->desc, 0x80*sizeof(u16));
memcpy(entry->author, icon->author, 0x40*sizeof(u16));
}
static void parse_entry_smdh(Entry_s * entry, const u16 * fallback_name)
{
char *info_buffer = NULL;
u64 size = load_data("/info.smdh", *entry, &info_buffer);
if(!size)
{
free(info_buffer);
info_buffer = NULL;
}
Icon_s * smdh = (Icon_s *)info_buffer;
parse_smdh(smdh, entry, fallback_name);
}
static C2D_Image * load_entry_icon(Entry_s entry)
{
char *info_buffer = NULL;
@@ -120,7 +106,9 @@ static C2D_Image * load_entry_icon(Entry_s entry)
if(!size) return NULL;
Icon_s * smdh = (Icon_s *)info_buffer;
return loadTextureIcon(smdh);
C2D_Image* out = loadTextureIcon(smdh);
free(info_buffer);
return out;
}
typedef int (*sort_comparator)(const void *, const void *);
@@ -202,20 +190,21 @@ Result load_entries(const char * loading_path, Entry_List_s * list)
}
else
{
const ssize_t len = strulen(path, 0x106);
struacat(path, "/info.smdh");
u32 size = file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, &buf);
if (size == 0) continue;
memset(&path[len], 0, (0x106 - len) * sizeof(u16));
}
free(buf);
list->entries_count++;
Entry_s * new_list = realloc(list->entries, list->entries_count * sizeof(Entry_s));
if(new_list == NULL)
{
free(list->entries);
list->entries = NULL;
res = -1;
DEBUG("break\n");
// out of memory: still allow use of currently loaded entries.
// Many things might die, depending on the heap layout after
list->entries_count--;
free(buf);
break;
}
else
@@ -223,12 +212,11 @@ Result load_entries(const char * loading_path, Entry_List_s * list)
Entry_s * current_entry = &(list->entries[list->entries_count-1]);
memset(current_entry, 0, sizeof(Entry_s));
parse_smdh((Icon_s *)buf, current_entry, dir_entry.name);
free(buf);
struacat(current_entry->path, loading_path);
strucat(current_entry->path, dir_entry.name);
memcpy(current_entry->path, path, 0x106 * sizeof(u16));
current_entry->is_zip = !strcmp(dir_entry.shortExt, "ZIP");
parse_entry_smdh(current_entry, dir_entry.name);
}
FSDIR_Close(dir_handle);