Fixed some minor memory leaks in UIModeController, InputManager and Font.

This commit is contained in:
Leon Styhre 2021-03-19 18:34:10 +01:00
parent adaec71f5b
commit 08e6f1b0dd
5 changed files with 26 additions and 0 deletions

View file

@ -26,6 +26,14 @@ UIModeController* UIModeController::getInstance()
return sInstance;
}
void UIModeController::deinit()
{
if (sInstance) {
delete sInstance;
sInstance = nullptr;
}
}
UIModeController::UIModeController() : mPassKeyCounter(0)
{
mPassKeySequence = Settings::getInstance()->getString("UIMode_passkey");

View file

@ -23,6 +23,7 @@ class UIModeController
{
public:
static UIModeController* getInstance();
static void deinit();
// Monitor input for UI mode change, returns true (consumes input) when a UI mode
// change is triggered.

View file

@ -83,6 +83,7 @@ ViewController::~ViewController()
{
assert(sInstance == this);
sInstance = nullptr;
UIModeController::deinit();
}
void ViewController::noSystemsFileDialog()

View file

@ -174,6 +174,11 @@ void InputManager::deinit()
SDL_JoystickEventState(SDL_DISABLE);
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
if (sInstance) {
delete sInstance;
sInstance = nullptr;
}
}
int InputManager::getNumJoysticks()

View file

@ -93,6 +93,17 @@ Font::Font(int size, const std::string& path) : mSize(size), mPath(path)
Font::~Font()
{
unload(ResourceManager::getInstance());
auto fontEntry = sFontMap.find(std::pair<std::string, int>(mPath, mSize));
if (fontEntry != sFontMap.cend()) {
sFontMap.erase(fontEntry);
}
if (sFontMap.empty() && sLibrary) {
FT_Done_FreeType(sLibrary);
sLibrary = nullptr;
}
}
void Font::reload(std::shared_ptr<ResourceManager>& /*rm*/)