TASEmulators / BizHawk

BizHawk is a multi-system emulator written in C#. BizHawk provides nice features for casual gamers such as full screen, and joypad support in addition to full rerecording and debugging tools for all system cores.
http://tasvideos.org/BizHawk.html
Other
2.2k stars 385 forks source link

Rewinder with delta compression gets stuck once a frame is not stored. #2866

Closed dacin21 closed 3 years ago

dacin21 commented 3 years ago

Summary

If delta compression is enabled and the max buffer size and desired frame length are configured in a way that the RewindFrequency is not 1, i.e. that some frames are not captured in the rewind buffer, then the rewinder refuses to store any frames after the first 2.

I think this might be caused by the following lines

https://github.com/TASVideos/BizHawk/blob/09afbdd6eb0cce9b56f00c7ab8bf5e381d5f9826/src/BizHawk.Client.Common/rewind/ZeldaWinder.cs#L109-L110

If the if statement is entered, then _masterFrame won't change, so the if statement will be entered again next time. In other words, as soon as one frame is not captured, no future frames will ever be captured.

Repro

  1. Open Bizhawk
  2. Emulation > Pause (pauses the emulator)
  3. File > Open Rom > open a Super Mario World rom. (I suppose other games would work too, but this is the one I used.)
  4. Config > Rewind & States.
    • Enable rewinds
    • Set buffer size to 2^6 = 64 (i.e. some small value).
    • Set Desired frame length to 50'000 (i.e. some value ≥ 2⋅Est. storage).
    • Enable "Use delta compression (...)".
    • Click "OK" to close the configuration window.
  5. Emulation > Pause (unpauses the emulator)
  6. Let the game run for a while. (You can see the effect after a few seconds, but it remains even after letting the game run for 60'000 frames.)
  7. Config > Rewind & States.
    • We see that only 2 frames have been captured, even though the buffer should be full by now (since we set it to 50'000 frames).
    • Click "cancel" to close the configuration window.
  8. Press the rewind key ('E' by default). This rewinds the game all the way back to frame 2. This further confirms that no more frames have been captured after the first two.

Note that this only happens with delta compression and only happens if the rewind buffer doesn't just capture every frame. In particular, the "Desired frame length" has to be set to a large enough value.

Host env.

nattthebear commented 3 years ago

Thanks for the detailed repro, and I agree, the code is broken and you've found the broken line. I'll need to think a bit on how to fix it properly.

nattthebear commented 3 years ago

Please retest on 1c3eb45

dacin21 commented 3 years ago

https://github.com/TASVideos/BizHawk/commit/1c3eb451b295a20405edcb706a5e0b438a26d241 fixes this for me. Rewinds are now properly captured and the buffer is full right around the 50'000 frames mark.

nattthebear commented 3 years ago

Great. I'll push this to master as soon as I clean up the code some more.