Fix potential crash in savestate loading
Also throw when attempting to create such an invalid savestate. No idea yet how that can happen but apparently it can.
This commit is contained in:
parent
aeb80e5810
commit
6364475b21
|
@ -135,6 +135,12 @@ namespace BizHawk.Client.Common
|
|||
stateFrame = newLog.Count; // In case the frame count failed to parse, revert to using the entire state input log
|
||||
}
|
||||
|
||||
if (stateFrame > newLog.Count)
|
||||
{
|
||||
errorMessage = $"Savestate has invalid frame number {stateFrame} (expected maximum {newLog.Count})";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Log.Count < stateFrame)
|
||||
{
|
||||
if (this.IsFinished())
|
||||
|
|
|
@ -104,6 +104,13 @@ namespace BizHawk.Client.Common
|
|||
bs.PutLump(BinaryStateLump.Input,
|
||||
tw =>
|
||||
{
|
||||
// TODO: this should not happen and no exception should be thrown here.
|
||||
// Just make this noisy for now until the issue is fixed.
|
||||
if (_movieSession.Movie.FrameCount < _emulator.Frame)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Tried to create a savestate at frame {_emulator.Frame}, but only got a log of length {_movieSession.Movie.FrameCount}!");
|
||||
}
|
||||
// this never should have been a core's responsibility
|
||||
tw.WriteLine("Frame {0}", _emulator.Frame);
|
||||
_movieSession.HandleSaveState(tw);
|
||||
|
|
Loading…
Reference in New Issue