Skip to content

Commit

Permalink
Fix savestating being possible after movie has finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Morilli committed Jul 10, 2024
1 parent 662fd83 commit e9d6716
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/BizHawk.Client.Common/savestates/SavestateFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

Expand Down Expand Up @@ -91,13 +92,7 @@ public void Create(string filename, SaveStateConfig config)
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}!");
}
Debug.Assert(_movieSession.Movie.FrameCount >= _emulator.Frame);

This comment has been minimized.

Copy link
@YoshiRulz

YoshiRulz Jul 11, 2024

Member

Keep the message

edit: done in 616437f

This comment has been minimized.

Copy link
@Morilli

Morilli Jul 11, 2024

Author Collaborator

What message? The Debug.Assert should be plenty meaningful on its own: The thing that is asserted should never happen.

This comment has been minimized.

Copy link
@YoshiRulz

YoshiRulz Jul 11, 2024

Member

If there are multiple Debug.Assert calls in the same method (incl. inlined ones!) then you won't be able to distinguish them from a stacktrace. Rule SA1405, which I plan on enabling soon, will enforce a message.

This comment has been minimized.

Copy link
@Morilli

Morilli Jul 11, 2024

Author Collaborator

I'll have to look into how this actually presents itself, but I don't think annotating a Debug.Assert should be necessary. I would expect the debug information compiled into the assemblies to include enough information.

// this never should have been a core's responsibility
tw.WriteLine("Frame {0}", _emulator.Frame);
_movieSession.HandleSaveState(tw);
Expand Down
6 changes: 6 additions & 0 deletions src/BizHawk.Client.EmuHawk/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4331,6 +4331,12 @@ public void SaveState(string path, string userFriendlyStateName, bool fromLua =
return;
}

if (MovieSession.Movie.IsFinished())
{
OSD.AddMessage("Cannot savestate after movie end!");
return;
}

try
{
new SavestateFile(Emulator, MovieSession, MovieSession.UserBag).Create(path, Config.Savestates);
Expand Down

0 comments on commit e9d6716

Please sign in to comment.