Improved cleanup code on shutdown

This commit is contained in:
Sour 2018-06-09 15:42:27 -04:00
parent c22c5b2134
commit b6767f355d
3 changed files with 12 additions and 2 deletions

View file

@ -44,7 +44,7 @@ IAudioDevice *_soundManager = nullptr;
IKeyManager *_keyManager = nullptr;
unique_ptr<ShortcutKeyHandler> _shortcutKeyHandler;
void* _windowHandle = nullptr;
void* _windowHandle = nullptr;
void* _viewerHandle = nullptr;
string _returnString;
string _logString;
@ -341,6 +341,11 @@ namespace InteropEmu {
delete _soundManager;
_soundManager = nullptr;
}
if(_keyManager) {
delete _keyManager;
_keyManager = nullptr;
}
_shortcutKeyHandler.reset();
}
DllExport void __stdcall TakeScreenshot() { VideoDecoder::GetInstance()->TakeScreenshot(); }

View file

@ -244,6 +244,7 @@ WindowsKeyManager::WindowsKeyManager(HWND hWnd)
WindowsKeyManager::~WindowsKeyManager()
{
_stopUpdateDeviceThread = true;
_stopSignal.Signal();
_updateDeviceThread.join();
}
@ -265,7 +266,8 @@ void WindowsKeyManager::StartUpdateDeviceThread()
_directInput->UpdateDeviceList();
Console::Resume();
}
std::this_thread::sleep_for(std::chrono::duration<int, std::milli>(5000));
_stopSignal.Wait(5000);
}
});
}

View file

@ -4,6 +4,7 @@
#include <unordered_map>
#include "../Core/IKeyManager.h"
#include "../Utilities/Timer.h"
#include "../Utilities/AutoResetEvent.h"
#include "XInputManager.h"
#include "DirectInputManager.h"
@ -25,6 +26,8 @@ class WindowsKeyManager : public IKeyManager
std::unordered_map<uint32_t, string> _keyNames;
std::unordered_map<uint32_t, string> _keyExtendedNames;
std::unordered_map<string, uint32_t> _keyCodes;
AutoResetEvent _stopSignal;
std::thread _updateDeviceThread;
atomic<bool> _stopUpdateDeviceThread = false;