# HG changeset patch # User Sam # Date 1674122406 -25200 # Node ID 7684744ab1a4e27d4580df60716eee01279032b2 # Parent 73d5e3c9a569a21ab64ce308780099bc00c7baa3 fix: quit early to prevent swapchain recreation after program termination diff -r 73d5e3c9a569 -r 7684744ab1a4 src/semicongine/engine.nim --- 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 diff -r 73d5e3c9a569 -r 7684744ab1a4 src/semicongine/vulkan_helpers.nim --- 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,