Skip to content

Commit

Permalink
Fixed|Cleanup: Crash during application termination
Browse files Browse the repository at this point in the history
The client shouldn't crash after a fatal error occurs.
  • Loading branch information
skyjake committed Nov 24, 2016
1 parent 2640985 commit d762626
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/clientapp.cpp
Expand Up @@ -238,7 +238,7 @@ DENG2_PIMPL(ClientApp)
{
try
{
ClientWindow::main().glActivate(); // for GL deinit
ClientWindow::glActiveMain(); // for GL deinit

LogBuffer::get().removeSink(logAlarm);

Expand Down
17 changes: 8 additions & 9 deletions doomsday/apps/client/src/main_client.cpp
@@ -1,7 +1,7 @@
/** @file main_client.cpp Client application entrypoint.
* @ingroup base
*
* @authors Copyright © 2012-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2012-2016 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2013 Daniel Swanson <danij@dengine.net>
*
* @par License
Expand All @@ -22,15 +22,14 @@
/**
* @page mainFlow Engine Control Flow
*
* The main Qt application instance is ClientApp, based on de::GuiApp, a slightly
* modified version of the normal QApplication: it catches stray exceptions and forces a
* clean shutdown of the application.
* The main Qt application instance is ClientApp, based on de::BaseGuiApp.
*
* The application's event loop is started as soon as the main window has been created
* (but not shown yet). After the window appears with a fully functional OpenGL drawing
* surface, the rest of the engine initialization is completed. This is done via a
* callback in the Canvas class that gets called when the window actually appears on
* screen (with empty contents).
* The event loop is started after the application has been initialized. Initialization
* comprises the creation of subsystems and the main window. As a final step during
* initialization, the "bootstrap" script is executed. At this point, the main window is
* not visible yet. After the window appears with a fully functional OpenGL drawing
* surface, the rest of the engine initialization is completed. This is done via an
* observer audience in the de::GLWindow class.
*
* The application's refresh loop is controlled by de::Loop. Before each frame, clock
* time advances and de::Loop's iteration audience is notified. This is observed by
Expand Down
10 changes: 6 additions & 4 deletions doomsday/apps/client/src/sys_system.cpp
Expand Up @@ -135,10 +135,12 @@ void Sys_Shutdown()
Net_Shutdown();

#ifdef __CLIENT__
// Let's shut down sound first, so Windows' HD-hogging doesn't jam
// the MUS player (would produce horrible bursts of notes).
App_AudioSystem().deinitPlayback();

if (ClientApp::hasAudioSystem())
{
// Let's shut down sound first, so Windows' HD-hogging doesn't jam
// the MUS player (would produce horrible bursts of notes).
App_AudioSystem().deinitPlayback();
}
GL_Shutdown();
if(ClientApp::hasInputSystem())
{
Expand Down
8 changes: 5 additions & 3 deletions doomsday/apps/libdoomsday/src/doomsdayapp.cpp
Expand Up @@ -131,9 +131,11 @@ DENG2_PIMPL(DoomsdayApp)

~Impl()
{
// Save any changes to the game profiles.
gameProfiles.serialize();

if (initialized)
{
// Save any changes to the game profiles.
gameProfiles.serialize();
}
theDoomsdayApp = nullptr;
}

Expand Down
5 changes: 1 addition & 4 deletions doomsday/sdk/libappfw/src/baseguiapp.cpp
Expand Up @@ -132,10 +132,7 @@ BaseGuiApp::BaseGuiApp(int &argc, char **argv)

void BaseGuiApp::glDeinit()
{
if (GLWindow::mainExists())
{
GLWindow::main().glActivate();
}
GLWindow::glActiveMain();

d->vr.oculusRift().deinit();
d->shaders.clear();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libgui/include/de/gui/glwindow.h
Expand Up @@ -47,7 +47,6 @@ class LIBGUI_PUBLIC GLWindow : public QOpenGLWindow, public Asset
public:
typedef Vector2ui Size;


/**
* Notified when the canvas's GL state needs to be initialized. The OpenGL
* context and drawing surface are not ready before this occurs. This gets
Expand Down Expand Up @@ -176,6 +175,7 @@ class LIBGUI_PUBLIC GLWindow : public QOpenGLWindow, public Asset
public:
static bool mainExists();
static GLWindow &main();
static void glActiveMain();
static void setMain(GLWindow *window);

protected:
Expand Down
5 changes: 5 additions & 0 deletions doomsday/sdk/libgui/src/glwindow.cpp
Expand Up @@ -497,6 +497,11 @@ GLWindow &GLWindow::main() // static
return *mainWindow;
}

void GLWindow::glActiveMain()
{
if (mainExists()) main().glActivate();
}

void GLWindow::setMain(GLWindow *window) // static
{
mainWindow = window;
Expand Down

0 comments on commit d762626

Please sign in to comment.