Skip to content

Commit

Permalink
savestates: Only notify SAVECOMPLETE once save is actually done
Browse files Browse the repository at this point in the history
Fixes #1031
  • Loading branch information
alice-mkh committed Jul 2, 2024
1 parent 5340daf commit 8b75435
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/main/savestates.c
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,7 @@ static void savestates_save_m64p_work(struct work_struct *work)
{
main_message(M64MSG_STATUS, OSD_BOTTOM_LEFT, "Could not open state file: %s", save->filepath);
free(save->data);
StateChanged(M64CORE_STATE_SAVECOMPLETE, 0);
return;
}

Expand All @@ -1502,6 +1503,7 @@ static void savestates_save_m64p_work(struct work_struct *work)
main_message(M64MSG_STATUS, OSD_BOTTOM_LEFT, "Could not write data to state file: %s", save->filepath);
gzclose(f);
free(save->data);
StateChanged(M64CORE_STATE_SAVECOMPLETE, 0);
return;
}

Expand All @@ -1512,6 +1514,7 @@ static void savestates_save_m64p_work(struct work_struct *work)
free(save);

SDL_UnlockMutex(savestates_lock);
StateChanged(M64CORE_STATE_SAVECOMPLETE, 1);
}

static int savestates_save_m64p(const struct device* dev, char *filepath)
Expand All @@ -1530,6 +1533,7 @@ static int savestates_save_m64p(const struct device* dev, char *filepath)
save = malloc(sizeof(*save));
if (!save) {
main_message(M64MSG_STATUS, OSD_BOTTOM_LEFT, "Insufficient memory to save state.");
StateChanged(M64CORE_STATE_SAVECOMPLETE, 0);
return 0;
}

Expand All @@ -1548,6 +1552,7 @@ static int savestates_save_m64p(const struct device* dev, char *filepath)
free(save->filepath);
free(save);
main_message(M64MSG_STATUS, OSD_BOTTOM_LEFT, "Insufficient memory to save state.");
StateChanged(M64CORE_STATE_SAVECOMPLETE, 0);
return 0;
}

Expand Down Expand Up @@ -2121,6 +2126,7 @@ static int savestates_save_pj64_zip(const struct device* dev, char *filepath)
zipCloseFileInZip(zipfile); // This may fail, but we don't care
zipClose(zipfile, "");
}
StateChanged(M64CORE_STATE_SAVECOMPLETE, 1);
return 1;
}

Expand All @@ -2137,17 +2143,20 @@ static int savestates_save_pj64_unc(const struct device* dev, char *filepath)
if (f == NULL)
{
main_message(M64MSG_STATUS, OSD_BOTTOM_LEFT, "Could not create PJ64 state file: %s", filepath);
StateChanged(M64CORE_STATE_SAVECOMPLETE, 0);
return 0;
}

if (!savestates_save_pj64(dev, filepath, f, write_data_to_file))
{
fclose(f);
StateChanged(M64CORE_STATE_SAVECOMPLETE, 0);
return 0;
}

main_message(M64MSG_STATUS, OSD_BOTTOM_LEFT, "Saved state to: %s", namefrompath(filepath));
fclose(f);
StateChanged(M64CORE_STATE_SAVECOMPLETE, 1);
return 1;
}

Expand Down Expand Up @@ -2177,13 +2186,14 @@ int savestates_save(void)
case savestates_type_m64p: ret = savestates_save_m64p(dev, filepath); break;
case savestates_type_pj64_zip: ret = savestates_save_pj64_zip(dev, filepath); break;
case savestates_type_pj64_unc: ret = savestates_save_pj64_unc(dev, filepath); break;
default: ret = 0; break;
default: ret = 0; StateChanged(M64CORE_STATE_SAVECOMPLETE, ret); break;
}
free(filepath);
}

// deliver callback to indicate completion of state saving operation
StateChanged(M64CORE_STATE_SAVECOMPLETE, ret);
else
{
StateChanged(M64CORE_STATE_SAVECOMPLETE, ret);
}

savestates_clear_job();
return ret;
Expand Down

0 comments on commit 8b75435

Please sign in to comment.