Skip to content

Commit 5d0efb5

Browse files
committed
Fixed sample app crashing when window is minimized
1 parent 9837451 commit 5d0efb5

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/VulkanSample.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,8 +2420,22 @@ static void PrintAllocatorStats()
24202420
#endif
24212421
}
24222422

2423+
static bool IsWindowMinimizedOrZeroSized()
2424+
{
2425+
if((g_hWnd == NULL) || IsIconic(g_hWnd))
2426+
return true;
2427+
2428+
RECT clientRect = {};
2429+
GetClientRect(g_hWnd, &clientRect);
2430+
return clientRect.right <= clientRect.left
2431+
|| clientRect.bottom <= clientRect.top;
2432+
}
2433+
24232434
static void RecreateSwapChain()
24242435
{
2436+
if(IsWindowMinimizedOrZeroSized())
2437+
return;
2438+
24252439
vkDeviceWaitIdle(g_hDevice);
24262440
DestroySwapchain(false);
24272441
CreateSwapchain();
@@ -2738,10 +2752,10 @@ int MainWindow()
27382752
TranslateMessage(&msg);
27392753
DispatchMessage(&msg);
27402754
}
2755+
else if(IsWindowMinimizedOrZeroSized())
2756+
Sleep(25);
27412757
else
2742-
{
27432758
DrawFrame();
2744-
}
27452759
}
27462760

27472761
return (int)msg.wParam;;

0 commit comments

Comments
 (0)