From 4edaa11478ad09da86bb79c399de35f722c318d4 Mon Sep 17 00:00:00 2001 From: bucanero Date: Fri, 27 Jan 2023 20:27:21 -0300 Subject: [PATCH] Fix save settings bug wait for thread before exit --- CHANGELOG.md | 1 + include/settings.h | 1 + source/main.c | 26 ++++++++++---------------- source/save_util.c | 10 +++++----- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85ac3ce..3b20d09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ All notable changes to the `apollo-ps3` project will be documented in this file. * Fix screen aspect ratio (Tiny3D viewport issue) * Fix list refresh bug with `.PSV` saves * Fix `.VM2` to `.VMC` export bug +* Fix bug when saving settings ### Misc diff --git a/include/settings.h b/include/settings.h index 9690b66..bc03150 100644 --- a/include/settings.h +++ b/include/settings.h @@ -51,6 +51,7 @@ void redetect_callback(int sel); void clearcache_callback(int sel); void upd_appdata_callback(int sel); void unzip_app_data(const char* zip_file); +void wait_save_thread(void); int save_xml_owner(const char *xmlfile, const char *owner); int read_xml_owner(const char *xmlfile, const char *owner); diff --git a/source/main.c b/source/main.c index 4e1ee33..a379cc8 100644 --- a/source/main.c +++ b/source/main.c @@ -162,17 +162,24 @@ static void release_all() if(inited & INITED_CALLBACK) sysUtilUnregisterCallback(SYSUTIL_EVENT_SLOT0); - if(inited & INITED_AUDIOPLAYER) - { } - if(inited & INITED_SOUNDLIB) SND_End(); + if(inited & INITED_AUDIOPLAYER) { + xmp_end_player(xmp); + xmp_release_module(xmp); + xmp_free_context(xmp); + } + if(inited & INITED_SPU) { sysSpuRawDestroy(spu); sysSpuImageClose(&spu_image); } + http_end(); + wait_save_thread(); + sysModuleUnload(SYSMODULE_PNGDEC); + inited=0; } @@ -416,16 +423,6 @@ void update_trophy_path(char* path) sprintf(path, TROPHY_PATH_HDD, apollo_config.user_id); } -static void exiting() -{ - xmp_end_player(xmp); - xmp_release_module(xmp); - xmp_free_context(xmp); - - http_end(); - sysModuleUnload(SYSMODULE_PNGDEC); -} - static void registerSpecialChars() { // Register save tags @@ -478,8 +475,6 @@ s32 main(s32 argc, const char* argv[]) sysModuleLoad(SYSMODULE_PNGDEC); - atexit(exiting); // Tiny3D register the event 3 and do exit() call when you exit to the menu - // register exit callback if(sysUtilRegisterCallback(SYSUTIL_EVENT_SLOT0, sys_callback, NULL)==0) inited |= INITED_CALLBACK; @@ -567,7 +562,6 @@ s32 main(s32 argc, const char* argv[]) } release_all(); - http_end(); if (file_exists("/dev_hdd0/mms/db.err") == SUCCESS) sys_reboot(); diff --git a/source/save_util.c b/source/save_util.c index 2a51012..641c08e 100644 --- a/source/save_util.c +++ b/source/save_util.c @@ -66,10 +66,10 @@ typedef struct SaveData { s32 result; } save_metadata_t; -sys_ppu_thread_t save_tid = 0; -save_metadata_t* save_data; -u8* file_data; -u64 file_size; +static sys_ppu_thread_t save_tid = 0; +static save_metadata_t* save_data; +static u8* file_data; +static u64 file_size; static void saveload_game_status_cb (sysSaveCallbackResult *result, sysSaveStatusIn *in, sysSaveStatusOut *out) { @@ -339,7 +339,7 @@ static int _create_thread (int flags, const char *folder, const char *filename) return TRUE; } -static void wait_save_thread() +void wait_save_thread(void) { while (save_tid != 0) { usleep(100*1000);