NetPlay: Fixed crash when host loaded a game while no game was loaded (ConfigChanged notification was sent and an empty snapshot was sent to clients)

This commit is contained in:
Souryo 2016-02-10 21:41:51 -05:00
parent b4abaf36dc
commit eb80a443b7
3 changed files with 15 additions and 14 deletions

View file

@ -60,7 +60,7 @@ void Console::Initialize(string romFilename, stringstream *filestream, string ip
_memoryManager->RegisterIODevice(_apu.get());
_memoryManager->RegisterIODevice(_controlManager.get());
UpdateNesModel();
UpdateNesModel(false);
_initialized = true;
@ -208,7 +208,9 @@ void Console::Run()
_runLock.Acquire();
_stopLock.Acquire();
targetTime = UpdateNesModel();
_model = NesModel::Auto;
targetTime = UpdateNesModel(false);
VideoDecoder::GetInstance()->StartThread();
@ -250,7 +252,7 @@ void Console::Run()
//Get next target time, and adjust based on whether we are ahead or behind
double timeLag = EmulationSettings::GetEmulationSpeed() == 0 ? 0 : clockTimer.GetElapsedMS() - targetTime;
targetTime = UpdateNesModel();
targetTime = UpdateNesModel(true);
clockTimer.Reset();
targetTime -= timeLag;
if(targetTime < 0) {
@ -275,7 +277,7 @@ void Console::Run()
_runLock.Release();
}
double Console::UpdateNesModel()
double Console::UpdateNesModel(bool sendNotification)
{
bool configChanged = false;
if(EmulationSettings::NeedControllerUpdate()) {
@ -309,7 +311,7 @@ double Console::UpdateNesModel()
_ppu->SetNesModel(model);
_apu->SetNesModel(model);
if(configChanged) {
if(configChanged && sendNotification) {
MessageManager::SendNotification(ConsoleNotificationType::ConfigChanged);
}

View file

@ -38,7 +38,7 @@ class Console
void ResetComponents(bool softReset);
void Initialize(string filename, stringstream *filestream = nullptr, string ipsFilename = "");
double UpdateNesModel();
double UpdateNesModel(bool sendNotification);
public:
Console();

View file

@ -174,8 +174,6 @@ void ControlManager::WriteRAM(uint16_t addr, uint8_t value)
void ControlManager::StreamState(bool saving)
{
Stream<bool>(_refreshState);
//Restore controllers that were being used at the time the snapshot was made
//This is particularely important to ensure proper sync during NetPlay
ControllerType controllerTypes[4];
@ -193,6 +191,7 @@ void ControlManager::StreamState(bool saving)
}
}
Stream<bool>(_refreshState);
Stream<NesModel>(nesModel);
Stream<ExpansionPortDevice>(expansionDevice);
Stream<ConsoleType>(consoleType);
@ -216,13 +215,13 @@ void ControlManager::StreamState(bool saving)
}
UpdateControlDevices();
}
if(GetControlDevice(0)) {
Stream(GetControlDevice(0));
}
if(GetControlDevice(1)) {
Stream(GetControlDevice(1));
}
if(GetControlDevice(0)) {
Stream(GetControlDevice(0).get());
}
if(GetControlDevice(1)) {
Stream(GetControlDevice(1).get());
}
}