Skip to content

Commit

Permalink
Fix save settings bug
Browse files Browse the repository at this point in the history
wait for thread before exit
  • Loading branch information
bucanero committed Jan 27, 2023
1 parent 36168e6 commit 4edaa11
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 10 additions & 16 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();

Expand Down
10 changes: 5 additions & 5 deletions source/save_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4edaa11

Please sign in to comment.