changeset 51:7684744ab1a4

fix: quit early to prevent swapchain recreation after program termination
author Sam <sam@basx.dev>
date Thu, 19 Jan 2023 17:00:06 +0700
parents 73d5e3c9a569
children 5ab7fb4d9ee9
files src/semicongine/engine.nim src/semicongine/vulkan_helpers.nim
diffstat 2 files changed, 9 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/semicongine/engine.nim	Thu Jan 19 16:41:50 2023 +0700
+++ b/src/semicongine/engine.nim	Thu Jan 19 17:00:06 2023 +0700
@@ -711,18 +711,17 @@
 
 proc run*(engine: var Engine, pipeline: var RenderPipeline, globalUpdate: proc(engine: var Engine, dt: float32)) =
   var
-    killed = false
     currentFrame = 0
     resized = false
     lastUpdate = getTime()
 
-  while not killed:
-
+  while true:
     # process input
     engine.input.keysPressed = {}
     engine.input.keysReleased = {}
     engine.input.mousePressed = {}
     engine.input.mouseReleased = {}
+    var killed = false
     for event in engine.window.pendingEvents():
       case event.eventType:
         of Quit:
@@ -746,6 +745,8 @@
           engine.input.mouseY = event.y
         else:
           discard
+    if killed: # at least on windows we should return immediately as swapchain recreation will fail after kill
+      break
 
     # game logic update
     let
--- a/src/semicongine/vulkan_helpers.nim	Thu Jan 19 16:41:50 2023 +0700
+++ b/src/semicongine/vulkan_helpers.nim	Thu Jan 19 17:00:06 2023 +0700
@@ -100,21 +100,21 @@
 
 proc getDeviceSurfaceFormats*(device: VkPhysicalDevice, surface: VkSurfaceKHR): seq[VkSurfaceFormatKHR] =
   var n_formats: uint32
-  checkVkResult vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, addr(n_formats), nil);
+  checkVkResult vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, addr(n_formats), nil)
   result = newSeq[VkSurfaceFormatKHR](n_formats)
   checkVkResult vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, addr(n_formats), addrOrNil(result))
 
 
 proc getDeviceSurfacePresentModes*(device: VkPhysicalDevice, surface: VkSurfaceKHR): seq[VkPresentModeKHR] =
   var n_modes: uint32
-  checkVkResult vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, addr(n_modes), nil);
+  checkVkResult vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, addr(n_modes), nil)
   result = newSeq[VkPresentModeKHR](n_modes)
   checkVkResult vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, addr(n_modes), addrOrNil(result))
 
 
 proc getSwapChainImages*(device: VkDevice, swapChain: VkSwapchainKHR): seq[VkImage] =
   var n_images: uint32
-  checkVkResult vkGetSwapchainImagesKHR(device, swapChain, addr(n_images), nil);
+  checkVkResult vkGetSwapchainImagesKHR(device, swapChain, addr(n_images), nil)
   result = newSeq[VkImage](n_images)
   checkVkResult vkGetSwapchainImagesKHR(device, swapChain, addr(n_images), addr(result[0]))
 
@@ -211,8 +211,8 @@
     ppEnabledExtensionNames: cast[ptr UncheckedArray[cstring]](addr(requiredExtensions))
   )
   checkVkResult vkCreateDevice(physicalDevice, addr(deviceCreateInfo), nil, addr(result[0]))
-  vkGetDeviceQueue(result[0], graphicsQueueFamily, 0'u32, addr(result[1]));
-  vkGetDeviceQueue(result[0], presentationQueueFamily, 0'u32, addr(result[2]));
+  vkGetDeviceQueue(result[0], graphicsQueueFamily, 0'u32, addr(result[1]))
+  vkGetDeviceQueue(result[0], presentationQueueFamily, 0'u32, addr(result[2]))
 
 proc debugCallback*(
   messageSeverity: VkDebugUtilsMessageSeverityFlagBitsEXT,