Skip to content

Commit

Permalink
Rewind: Fixed partial desync of input data when rewind stops
Browse files Browse the repository at this point in the history
This could potentially cause desyncs on subsequent rewinds, but most obviously it caused rewinding during movie playback to break movie playback entirely (because some inputs were handled by the rewind, while others were handled by the movie, causing the _deviceIndex value to be out of sync with its expected value)
  • Loading branch information
SourMesen committed Dec 13, 2024
1 parent 0ff6e6a commit 84919bc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
7 changes: 6 additions & 1 deletion Core/Shared/Movies/MesenMovie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ void MesenMovie::Stop()
bool MesenMovie::SetInput(BaseControlDevice *device)
{
uint32_t inputRowIndex = _controlManager->GetPollCounter();
_lastPollCounter = inputRowIndex;

if(_lastPollCounter != inputRowIndex) {
_lastPollCounter = inputRowIndex;
assert(_deviceIndex == 0);
_deviceIndex = 0;
}

if(_inputData.size() > inputRowIndex && _inputData[inputRowIndex].size() > _deviceIndex) {
device->SetTextState(_inputData[inputRowIndex][_deviceIndex]);
Expand Down
16 changes: 10 additions & 6 deletions Core/Shared/RewindManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void RewindManager::ProcessNotification(ConsoleNotificationType type, void * par
_framesToFastForward--;
_currentHistory.FrameCount++;
if(_framesToFastForward == 0) {
for(int i = 0; i < 4; i++) {
for(int i = 0; i < BaseControlDevice::PortCount; i++) {
size_t numberToRemove = _currentHistory.InputLogs[i].size();
_currentHistory.InputLogs[i] = _historyBackup.front().InputLogs[i];
for(size_t j = 0; j < numberToRemove; j++) {
Expand Down Expand Up @@ -407,11 +407,15 @@ void RewindManager::RecordInput(vector<shared_ptr<BaseControlDevice>> devices)
bool RewindManager::SetInput(BaseControlDevice *device)
{
uint8_t port = device->GetPort();
if(!_currentHistory.InputLogs[port].empty() && IsRewinding()) {
ControlDeviceState state = _currentHistory.InputLogs[port].front();
_currentHistory.InputLogs[port].pop_front();
device->SetRawState(state);
return true;
if(IsRewinding()) {
if(!_currentHistory.InputLogs[port].empty()) {
ControlDeviceState state = _currentHistory.InputLogs[port].front();
_currentHistory.InputLogs[port].pop_front();
device->SetRawState(state);
return true;
} else {
return false;
}
} else {
return false;
}
Expand Down
1 change: 1 addition & 0 deletions Core/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <thread>
#include <deque>
#include <algorithm>
#include <assert.h>

#include "Utilities/UTF8Util.h"

Expand Down

0 comments on commit 84919bc

Please sign in to comment.