Try to fix nasty corner cases of failing loads
Hopefully one no causes a desync if one tries to load state/movie that can't be loaded or resolve corrupt system using a savestate.
This commit is contained in:
parent
96d1ef665c
commit
bb54273daa
3 changed files with 20 additions and 11 deletions
22
mainloop.cpp
22
mainloop.cpp
|
@ -851,11 +851,15 @@ namespace
|
|||
}
|
||||
} bah;
|
||||
|
||||
//If there is a pending load, perform it.
|
||||
bool handle_load()
|
||||
//If there is a pending load, perform it. Return 1 on successful load, 0 if nothing to load, -1 on load
|
||||
//failing.
|
||||
int handle_load()
|
||||
{
|
||||
if(pending_load != "") {
|
||||
do_load_state(pending_load, loadmode);
|
||||
if(!do_load_state(pending_load, loadmode)) {
|
||||
pending_load = "";
|
||||
return -1;
|
||||
}
|
||||
redraw_framebuffer();
|
||||
pending_load = "";
|
||||
pending_reset_cycles = -1;
|
||||
|
@ -868,9 +872,9 @@ namespace
|
|||
window::notify_screen_update();
|
||||
window::poll_inputs();
|
||||
}
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//If there are pending saves, perform them.
|
||||
|
@ -993,7 +997,7 @@ void main_loop(struct loaded_rom& rom, struct moviefile& initial) throw(std::bad
|
|||
while(amode != ADVANCE_QUIT) {
|
||||
if(handle_corrupt()) {
|
||||
first_round = our_movie.is_savestate;
|
||||
just_did_loadstate = true;
|
||||
just_did_loadstate = first_round;
|
||||
continue;
|
||||
}
|
||||
long resetcycles = -1;
|
||||
|
@ -1013,11 +1017,15 @@ void main_loop(struct loaded_rom& rom, struct moviefile& initial) throw(std::bad
|
|||
if(!delayed_reset) {
|
||||
handle_saves();
|
||||
}
|
||||
if(handle_load()) {
|
||||
int r = handle_load();
|
||||
if(r > 0 || system_corrupt) {
|
||||
first_round = our_movie.is_savestate;
|
||||
amode = ADVANCE_PAUSE;
|
||||
just_did_loadstate = first_round;
|
||||
continue;
|
||||
} else if(r < 0) {
|
||||
//Not exactly desriable, but this at least won't desync.
|
||||
amode = ADVANCE_PAUSE;
|
||||
}
|
||||
}
|
||||
if(just_did_loadstate) {
|
||||
|
|
|
@ -303,7 +303,7 @@ void do_load_state(struct moviefile& _movie, int lmode)
|
|||
}
|
||||
|
||||
//Load state
|
||||
void do_load_state(const std::string& filename, int lmode)
|
||||
bool do_load_state(const std::string& filename, int lmode)
|
||||
{
|
||||
uint64_t origtime = get_ticks_msec();
|
||||
lua_callback_pre_load(filename);
|
||||
|
@ -315,7 +315,7 @@ void do_load_state(const std::string& filename, int lmode)
|
|||
} catch(std::exception& e) {
|
||||
messages << "Can't read movie/savestate '" << filename << "': " << e.what() << std::endl;
|
||||
lua_callback_err_load(filename);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
do_load_state(mfile, lmode);
|
||||
|
@ -327,6 +327,7 @@ void do_load_state(const std::string& filename, int lmode)
|
|||
} catch(std::exception& e) {
|
||||
messages << "Can't load movie/savestate '" << filename << "': " << e.what() << std::endl;
|
||||
lua_callback_err_load(filename);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ std::pair<std::string, std::string> split_author(const std::string& author) thro
|
|||
void do_save_state(const std::string& filename) throw(std::bad_alloc, std::runtime_error);
|
||||
void do_save_movie(const std::string& filename) throw(std::bad_alloc, std::runtime_error);
|
||||
void do_load_state(struct moviefile& _movie, int lmode);
|
||||
void do_load_state(const std::string& filename, int lmode);
|
||||
bool do_load_state(const std::string& filename, int lmode);
|
||||
|
||||
extern movie_logic movb;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue