From 6e06a9ac5299da538c03c2cf9a38373409cf71d5 Mon Sep 17 00:00:00 2001 From: Levi Pearson Date: Wed, 25 Jan 2017 22:58:45 -0700 Subject: [PATCH] Add cleanup of input handlers when shutting down; Remove C++11ism. --- RetroFE/Source/Control/InputHandler.h | 1 + RetroFE/Source/Control/UserInput.cpp | 8 ++++++++ RetroFE/Source/Control/UserInput.h | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/RetroFE/Source/Control/InputHandler.h b/RetroFE/Source/Control/InputHandler.h index 9996d4b..8ef88da 100644 --- a/RetroFE/Source/Control/InputHandler.h +++ b/RetroFE/Source/Control/InputHandler.h @@ -5,6 +5,7 @@ class InputHandler { public: + virtual ~InputHandler() {}; virtual bool update(SDL_Event &e) = 0; virtual bool pressed() = 0; virtual void reset() = 0; diff --git a/RetroFE/Source/Control/UserInput.cpp b/RetroFE/Source/Control/UserInput.cpp index 5002767..fc61d28 100644 --- a/RetroFE/Source/Control/UserInput.cpp +++ b/RetroFE/Source/Control/UserInput.cpp @@ -36,6 +36,14 @@ UserInput::UserInput(Configuration &c) UserInput::~UserInput() { + for (unsigned int i = 0; i < keyHandlers_.size(); ++i) + { + if (keyHandlers_[i].first) + { + delete keyHandlers_[i].first; + } + } + // This code causes an exception when a controller is attached; it's disabled to prevent crashes on exit. // for(std::vector::iterator it = joysticks_.begin(); it != joysticks_.end(); it++) // { diff --git a/RetroFE/Source/Control/UserInput.h b/RetroFE/Source/Control/UserInput.h index c08257d..25bec1d 100644 --- a/RetroFE/Source/Control/UserInput.h +++ b/RetroFE/Source/Control/UserInput.h @@ -64,7 +64,7 @@ private: bool MapKey(std::string keyDescription, KeyCode_E key, bool required); Configuration &config_; std::vector joysticks_; - std::vector> keyHandlers_; + std::vector > keyHandlers_; bool lastKeyState_[KeyCodeMax]; bool currentKeyState_[KeyCodeMax]; };