CDROM: Fix crash when loading save state from different system

This commit is contained in:
Connor McLaughlin
2020-04-08 13:08:27 +10:00
parent 9851b75368
commit 08567fedf4
3 changed files with 11 additions and 4 deletions

View File

@ -327,6 +327,7 @@ bool System::DoState(StateWrapper& sw)
std::string media_filename = m_cdrom->GetMediaFileName();
sw.Do(&media_filename);
bool media_is_bad = false;
if (sw.IsReading())
{
std::unique_ptr<CDImage> media;
@ -334,7 +335,10 @@ bool System::DoState(StateWrapper& sw)
{
media = CDImage::Open(media_filename.c_str());
if (!media)
Log_ErrorPrintf("Failed to open CD image from save state: '%s'", media_filename.c_str());
{
Log_ErrorPrintf("Failed to open CD image from save state: '%s'. Disc will be removed.", media_filename.c_str());
media_is_bad = true;
}
}
UpdateRunningGame(media_filename.c_str(), media.get());
@ -384,6 +388,9 @@ bool System::DoState(StateWrapper& sw)
if (!sw.DoMarker("Events") || !DoEventsState(sw))
return false;
if (media_is_bad)
m_cdrom->RemoveMedia(true);
return !sw.HasError();
}