From ca9109be750927a65277bfebdb4c39a71f870b3a Mon Sep 17 00:00:00 2001 From: wraitii Date: Tue, 28 May 2019 13:18:32 +0000 Subject: [PATCH] Fix a crash on some system when Alt-tabbing during game setup. Move checks for rendering a frame in Render() to avoid missing calls to this functions, which can crash on certain systems. Move the sound manager's idle task out of Render(). Move the buffer swapping in Render() since we do not need to swap buffers unless we are rendering. Patch By: Angen Reviewed By: wraitii Differential Revision: https://code.wildfiregames.com/D1495 This was SVN commit r22314. --- source/main.cpp | 15 +++++---------- source/ps/GameSetup/GameSetup.cpp | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index bd00fd3903..7e16222744 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -79,6 +79,7 @@ that of Atlas depending on commandline parameters. #include "scriptinterface/ScriptEngine.h" #include "simulation2/Simulation2.h" #include "simulation2/system/TurnManager.h" +#include "soundmanager/ISoundManager.h" #if OS_UNIX #include // geteuid @@ -407,16 +408,10 @@ static void Frame() g_Console->Update(realTimeSinceLastFrame); ogl_WarnIfError(); - // We do not have to render an inactive fullscreen frame, because it can - // lead to errors for some graphic card families. - if (!g_app_minimized && (g_app_has_focus || !g_VideoMode.IsInFullscreen())) - { - Render(); + if (g_SoundManager) + g_SoundManager->IdleTask(); - PROFILE3("swap buffers"); - SDL_GL_SwapWindow(g_VideoMode.GetWindow()); - } - ogl_WarnIfError(); + Render(); g_Profiler.Frame(); diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index 3d9f2450d3..924766faaf 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -188,14 +188,21 @@ void GUI_DisplayLoadProgress(int percent, const wchar_t* pending_task) g_GUI->GetActiveGUI()->SendEventToAll("progress"); } - +void SwapBuffers() +{ + PROFILE3("swap buffers"); + SDL_GL_SwapWindow(g_VideoMode.GetWindow()); + ogl_WarnIfError(); +} void Render() { - PROFILE3("render"); + // Do not render if not focused while in fullscreen or minimised, + // as that triggers a difficult-to-reproduce crash on some graphic cards. + if (g_app_minimized || (!g_app_has_focus && g_VideoMode.IsInFullscreen())) + return; - if (g_SoundManager) - g_SoundManager->IdleTask(); + PROFILE3("render"); ogl_WarnIfError(); @@ -330,6 +337,8 @@ void Render() g_Profiler2.RecordGPUFrameEnd(); ogl_WarnIfError(); + + SwapBuffers(); } ErrorReactionInternal psDisplayError(const wchar_t* UNUSED(text), size_t UNUSED(flags))