Mac: fix a crash caused by a race condition when switching ROMs

This commit is contained in:
Michael Buckley 2020-01-05 15:50:17 -08:00
parent 89f480207d
commit c12415f351
2 changed files with 21 additions and 49 deletions

View File

@ -102,8 +102,7 @@ int macFastForwardRate = 5,
unsigned long spcFileCount = 0, unsigned long spcFileCount = 0,
pngFileCount = 0; pngFileCount = 0;
bool8 finished = false, bool8 cartOpen = false,
cartOpen = false,
autofire = false; autofire = false;
bool8 fullscreen = false, bool8 fullscreen = false,
@ -2992,56 +2991,24 @@ void QuitWithFatalError ( NSString *message)
- (void)start - (void)start
{ {
if (!finished)
{
#ifdef DEBUGGER #ifdef DEBUGGER
CPU.Flags |= DEBUG_MODE_FLAG; CPU.Flags |= DEBUG_MODE_FLAG;
S9xDoDebug(); S9xDoDebug();
#endif #endif
lastFrame = GetMicroseconds(); lastFrame = GetMicroseconds();
frameCount = 0; frameCount = 0;
if (macFrameSkip < 0) if (macFrameSkip < 0)
skipFrames = 3; skipFrames = 3;
else else
skipFrames = macFrameSkip; skipFrames = macFrameSkip;
S9xInitDisplay(NULL, NULL); S9xInitDisplay(NULL, NULL);
[NSThread detachNewThreadWithBlock:^ [NSThread detachNewThreadWithBlock:^
{ {
MacSnes9xThread(NULL); MacSnes9xThread(NULL);
}];
dispatch_sync(dispatch_get_main_queue(), ^
{
if (!Settings.NetPlay || Settings.NetPlayServer)
{
SNES9X_SaveSRAM();
S9xResetSaveTimer(false);
S9xSaveCheatFile(S9xGetFilename(".cht", CHEAT_DIR));
}
S9xDeinitDisplay();
if (Settings.NetPlay)
{
if (!Settings.NetPlayServer)
{
// DeinitGameWindow();
cartOpen = false;
}
Settings.NetPlay = false;
Settings.NetPlayServer = false;
}
if (!finished)
{
[self start];
}
});
}];
}
} }
- (void)stop - (void)stop
@ -3183,6 +3150,13 @@ void QuitWithFatalError ( NSString *message)
- (BOOL)loadROM:(NSURL *)fileURL - (BOOL)loadROM:(NSURL *)fileURL
{ {
running = false;
while (!Settings.StopEmulation)
{
usleep(Settings.FrameTime);
}
if ( SNES9X_OpenCart(fileURL) ) if ( SNES9X_OpenCart(fileURL) )
{ {
SNES9X_Go(); SNES9X_Go();

View File

@ -431,8 +431,6 @@ void SNES9X_Quit (void)
S9xResetSaveTimer(false); S9xResetSaveTimer(false);
S9xSaveCheatFile(S9xGetFilename(".cht", CHEAT_DIR)); S9xSaveCheatFile(S9xGetFilename(".cht", CHEAT_DIR));
} }
finished = true;
} }
void SNES9X_InitSound (void) void SNES9X_InitSound (void)