diff --git a/src/state.cpp b/src/state.cpp index 0c56db22..fe067870 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -890,6 +890,15 @@ void FCEUI_SaveState(const char *fname) int loadStateFailed = 0; // hack, this function should return a value instead +bool file_exists(const char * filename) +{ + if (FILE * file = fopen(filename, "r")) //I'm sure, you meant for READING =) + { + fclose(file); + return true; + } + return false; +} void FCEUI_LoadState(const char *fname) { if(!FCEU_IsValidUI(FCEUI_LOADSTATE)) return; @@ -908,6 +917,11 @@ void FCEUI_LoadState(const char *fname) { FCEUI_MakeBackupMovie(false); //Backup the movie before the contents get altered, but do not display messages } + if (!file_exists(fname)) + { + loadStateFailed = 1; + return; // state doesn't exist; exit cleanly + } if(FCEUSS_Load(fname)) { //mbg todo netplay