Skip to content

Commit

Permalink
Restart the renderer only if window is currently active (fixes #165).
Browse files Browse the repository at this point in the history
  • Loading branch information
kondrak committed Feb 25, 2024
1 parent 288ec23 commit a856c1b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ref_vk/vk_rmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions win32/vk_imp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -428,6 +429,8 @@ void Vkimp_EndFrame (void)
*/
void Vkimp_AppActivate( qboolean active )
{
vkw_state.appActive = active;

if ( active )
{
SetForegroundWindow( vkw_state.hWnd );
Expand Down
1 change: 1 addition & 0 deletions win32/vk_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit a856c1b

Please sign in to comment.