From 68823adda3c8838733baea2405a75511baffe172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= Date: Tue, 7 Jul 2015 21:20:31 +0300 Subject: [PATCH] Fixed|Client: Null pointer access if shutting down too early The input system may be missing when an error occurs. --- doomsday/apps/client/include/clientapp.h | 1 + doomsday/apps/client/src/clientapp.cpp | 7 ++++++- doomsday/apps/client/src/sys_system.cpp | 6 +++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/doomsday/apps/client/include/clientapp.h b/doomsday/apps/client/include/clientapp.h index 80d8b61e79..b1f583e53a 100644 --- a/doomsday/apps/client/include/clientapp.h +++ b/doomsday/apps/client/include/clientapp.h @@ -76,6 +76,7 @@ class ClientApp : public de::BaseGuiApp static de::Games &games(); static de::WorldSystem &worldSystem(); + static bool hasInputSystem(); static bool hasRenderSystem(); public slots: diff --git a/doomsday/apps/client/src/clientapp.cpp b/doomsday/apps/client/src/clientapp.cpp index f5b2934268..f23d1aa0d5 100644 --- a/doomsday/apps/client/src/clientapp.cpp +++ b/doomsday/apps/client/src/clientapp.cpp @@ -504,6 +504,11 @@ InputSystem &ClientApp::inputSystem() return *a.d->inputSys; } +bool ClientApp::hasInputSystem() +{ + return ClientApp::app().d->inputSys != nullptr; +} + RenderSystem &ClientApp::renderSystem() { ClientApp &a = ClientApp::app(); @@ -513,7 +518,7 @@ RenderSystem &ClientApp::renderSystem() bool ClientApp::hasRenderSystem() { - return ClientApp::app().d->rendSys != 0; + return ClientApp::app().d->rendSys != nullptr; } ResourceSystem &ClientApp::resourceSystem() diff --git a/doomsday/apps/client/src/sys_system.cpp b/doomsday/apps/client/src/sys_system.cpp index 81820dc46d..34e6ad1f9c 100644 --- a/doomsday/apps/client/src/sys_system.cpp +++ b/doomsday/apps/client/src/sys_system.cpp @@ -134,9 +134,13 @@ void Sys_Shutdown() // Let's shut down sound first, so Windows' HD-hogging doesn't jam // the MUS player (would produce horrible bursts of notes). S_Shutdown(); + #ifdef __CLIENT__ GL_Shutdown(); - ClientApp::inputSystem().clearEvents(); + if(ClientApp::hasInputSystem()) + { + ClientApp::inputSystem().clearEvents(); + } #endif App_ClearGames();