From a856c1b038ba3df8bbccab8269dcf483e30a6415 Mon Sep 17 00:00:00 2001 From: Krzysztof Kondrak Date: Sun, 25 Feb 2024 23:42:18 +0100 Subject: [PATCH] Restart the renderer only if window is currently active (fixes #165). --- ref_vk/vk_rmain.c | 12 +++++++++++- win32/vk_imp.c | 3 +++ win32/vk_win.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ref_vk/vk_rmain.c b/ref_vk/vk_rmain.c index 5549808f..ce79b3f5 100644 --- a/ref_vk/vk_rmain.c +++ b/ref_vk/vk_rmain.c @@ -20,6 +20,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // vk_rmain.c #include "vk_local.h" +#ifdef _WIN32 +#include "../win32/vk_win.h" +#endif viddef_t vid; @@ -1320,7 +1323,14 @@ void R_EndFrame( void ) Vk_PollRestart_f(); // restart Vulkan renderer without rebuilding the entire window - if (R_ShouldRestart()) + if (R_ShouldRestart() +#ifdef _WIN32 + // Make sure that on Windows we restart the renderer only if the window is actually active. + // This fixes a bug when surface extents can be reported as {0, 0} if Alt-Tabbing in rapid succession. + // Also - one more reason not to use a 20+ year old windowing code! + && vkw_state.appActive +#endif + ) { vk_restart = false; vk_validation->modified = false; diff --git a/win32/vk_imp.c b/win32/vk_imp.c index d732de5e..efafa39e 100644 --- a/win32/vk_imp.c +++ b/win32/vk_imp.c @@ -97,6 +97,7 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen ) x = vid_xpos->value; y = vid_ypos->value; + vkw_state.appActive = false; vkw_state.hWnd = CreateWindowEx ( exstyle, WINDOW_CLASS_NAME, @@ -428,6 +429,8 @@ void Vkimp_EndFrame (void) */ void Vkimp_AppActivate( qboolean active ) { + vkw_state.appActive = active; + if ( active ) { SetForegroundWindow( vkw_state.hWnd ); diff --git a/win32/vk_win.h b/win32/vk_win.h index d6d946cd..8b2c61c5 100644 --- a/win32/vk_win.h +++ b/win32/vk_win.h @@ -34,6 +34,7 @@ typedef struct MONITORINFOEX monInfo; // active monitor info qboolean allowdisplaydepthchange; + qboolean appActive; // is the app window currently active? FILE *log_fp; } vkwstate_t;