From 0d22c16c4584cf01bc843c45c7582a57dff23c02 Mon Sep 17 00:00:00 2001
From: Jupeyy <jupjopjap@gmail.com>
Date: Sat, 27 Jan 2024 11:34:33 +0100
Subject: [PATCH] test

---
 .../client/backend/vulkan/backend_vulkan.cpp  | 41 +++++++++++++------
 src/engine/client/input.cpp                   |  1 +
 2 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/src/engine/client/backend/vulkan/backend_vulkan.cpp b/src/engine/client/backend/vulkan/backend_vulkan.cpp
index fec1ca928..45ddb839b 100644
--- a/src/engine/client/backend/vulkan/backend_vulkan.cpp
+++ b/src/engine/client/backend/vulkan/backend_vulkan.cpp
@@ -5540,7 +5540,7 @@ public:
 		if(OldSwapChainImageCount != m_SwapChainImageCount)
 		{
 			CleanupVulkan<false>();
-			InitVulkan<false>();
+			InitVulkan<false>(false);
 		}
 
 		if(OldSwapChain != VK_NULL_HANDLE)
@@ -6001,6 +6001,18 @@ public:
 		return VK_SAMPLE_COUNT_1_BIT;
 	}
 
+	bool CanCreateSwapchain(bool& CreateSwapchain) {
+		VkSurfaceCapabilitiesKHR VKSurfCap;
+		if(!GetSurfaceProperties(VKSurfCap)) {
+			return false;
+		}
+
+		auto Caps = GetSwapImageSize(VKSurfCap);
+		// if swapchain cannot be created, start paused
+		CreateSwapchain = Caps.m_SwapImageViewport.width == 0 || Caps.m_SwapImageViewport.height == 0;
+		return true;
+	}
+
 	int InitVulkanSwapChain(VkSwapchainKHR &OldSwapChain)
 	{
 		OldSwapChain = VK_NULL_HANDLE;
@@ -6091,7 +6103,7 @@ public:
 	}
 
 	template<bool IsFirstInitialization>
-	int InitVulkan()
+	int InitVulkan(bool SkipSwapchainInit)
 	{
 		if(!CreateDescriptorSetLayouts())
 			return -1;
@@ -6105,7 +6117,7 @@ public:
 		if(!CreateQuadUniformDescriptorSetLayout())
 			return -1;
 
-		if(IsFirstInitialization)
+		if(IsFirstInitialization && !SkipSwapchainInit)
 		{
 			VkSwapchainKHR OldSwapChain = VK_NULL_HANDLE;
 			if(InitVulkanSwapChain(OldSwapChain) != 0)
@@ -6550,9 +6562,19 @@ public:
 			*pCommand->m_pInitError = -2;
 			return false;
 		}
+		
+		bool CreateSwapchain = false;
+		if(!CanCreateSwapchain(CreateSwapchain)) {
+			*pCommand->m_pInitError = -2;
+			return false;
+		}
+		else if(!CreateSwapchain) {
+			// fake value
+			m_SwapChainImageCount = 2;
+		}
 
 		m_pStorage = pCommand->m_pStorage;
-		if(InitVulkan<true>() != 0)
+		if(InitVulkan<true>(!CreateSwapchain) != 0)
 		{
 			*pCommand->m_pInitError = -2;
 			return false;
@@ -6571,16 +6593,8 @@ public:
 			Primq += 4;
 		}
 
-
-		VkSurfaceCapabilitiesKHR VKSurfCap;
-		if(!GetSurfaceProperties(VKSurfCap)) {
-			*pCommand->m_pInitError = -2;
-			return false;
-		}
-
-		auto Caps = GetSwapImageSize(VKSurfCap);
 		// if swapchain cannot be created, start paused
-		if (Caps.m_SwapImageViewport.width == 0 || Caps.m_SwapImageViewport.height == 0) {
+		if (!CreateSwapchain) {
 			m_RenderingPaused = true;
 			m_RecreateSwapChain = true;
 		}
@@ -7480,6 +7494,7 @@ public:
 	[[nodiscard]] bool Cmd_WindowCreateNtf(const CCommandBuffer::SCommand_WindowCreateNtf *pCommand)
 	{
 		log_debug("vulkan", "creating new surface.");
+			dbg_msg("i", "was here2");
 		m_pWindow = SDL_GetWindowFromID(pCommand->m_WindowID);
 		if(m_RenderingPaused)
 		{
diff --git a/src/engine/client/input.cpp b/src/engine/client/input.cpp
index 7de5a9e31..e0e52e3ec 100644
--- a/src/engine/client/input.cpp
+++ b/src/engine/client/input.cpp
@@ -702,6 +702,7 @@ int CInput::Update()
 		case SDL_WINDOWEVENT:
 			// Ignore keys following a focus gain as they may be part of global
 			// shortcuts
+			dbg_msg("w-event", "with code %d", Event.window.event);
 			switch(Event.window.event)
 			{
 			case SDL_WINDOWEVENT_MOVED:
-- 
2.18.0.windows.1

