Fixed freezes/crashes when connecting/disconnecting

This commit is contained in:
Souryo 2014-07-06 21:11:52 -04:00
parent fd80330a61
commit 388d8c7d7a
3 changed files with 14 additions and 1 deletions

View file

@ -4,6 +4,7 @@
IControlDevice* ControlManager::ControlDevices[] = { nullptr, nullptr, nullptr, nullptr };
IControlDevice* ControlManager::OriginalControlDevices[] = { nullptr, nullptr, nullptr, nullptr };
IGameBroadcaster* ControlManager::GameBroadcaster = nullptr;
SimpleLock ControlManager::ControllerLock[4];
ControlManager::ControlManager()
{
@ -32,8 +33,10 @@ void ControlManager::BackupControlDevices()
void ControlManager::RestoreControlDevices()
{
for(int i = 0; i < 4; i++) {
ControlManager::ControllerLock[i].Acquire();
ControlDevices[i] = OriginalControlDevices[i];
}
ControlManager::ControllerLock[i].Release();
}
}
IControlDevice* ControlManager::GetControlDevice(uint8_t port)
@ -43,17 +46,22 @@ IControlDevice* ControlManager::GetControlDevice(uint8_t port)
void ControlManager::RegisterControlDevice(IControlDevice* controlDevice, uint8_t port)
{
ControlManager::ControllerLock[port].Acquire();
ControlManager::ControlDevices[port] = controlDevice;
ControlManager::ControllerLock[port].Release();
}
void ControlManager::UnregisterControlDevice(IControlDevice* controlDevice)
{
for(int i = 0; i < 4; i++) {
if(ControlManager::ControlDevices[i] == controlDevice) {
ControlManager::ControllerLock[i].Acquire();
ControlManager::ControlDevices[i] = nullptr;
ControlManager::ControllerLock[i].Release();
break;
}
}
}
void ControlManager::RefreshAllPorts()
@ -70,6 +78,7 @@ void ControlManager::RefreshStateBuffer(uint8_t port)
throw exception("Invalid port");
}
ControlManager::ControllerLock[port].Acquire();
IControlDevice* controlDevice = ControlManager::ControlDevices[port];
uint8_t state;
@ -82,6 +91,7 @@ void ControlManager::RefreshStateBuffer(uint8_t port)
state = 0x00;
}
}
ControlManager::ControllerLock[port].Release();
//Used when recording movies
Movie::Instance->RecordState(port, state);

View file

@ -6,6 +6,7 @@
#include "Movie.h"
#include "IGameBroadcaster.h"
#include "Snapshotable.h"
#include "../Utilities/SimpleLock.h"
class ControlManager : public Snapshotable, public IMemoryHandler
{
@ -13,6 +14,7 @@ class ControlManager : public Snapshotable, public IMemoryHandler
static IControlDevice* ControlDevices[4];
static IControlDevice* OriginalControlDevices[4];
static IGameBroadcaster* GameBroadcaster;
static SimpleLock ControllerLock[4];
bool _refreshState = false;
uint8_t _stateBuffer[4];

View file

@ -53,6 +53,7 @@ public:
~GameClientConnection()
{
_virtualControllers.clear();
ControlManager::RestoreControlDevices();
Console::DisplayMessage(L"Connection to server lost.");
}