From a1061c873a8313340bd25e66df9a4df72e9bf6d4 Mon Sep 17 00:00:00 2001 From: Slendi Date: Thu, 11 Dec 2025 13:06:42 +0200 Subject: [PATCH] Fix crash Signed-off-by: Slendi --- src/VulkanRenderer.cpp | 20 ++++++++++---------- thirdparty/smath | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/VulkanRenderer.cpp b/src/VulkanRenderer.cpp index 84ab932..7a3a55e 100644 --- a/src/VulkanRenderer.cpp +++ b/src/VulkanRenderer.cpp @@ -1132,16 +1132,13 @@ auto VulkanRenderer::create_image(void const *data, VkExtent3D size, vmaGetAllocationInfo(m_vk.allocator, upload_buffer.allocation, &info); void *mapped_data { reinterpret_cast(info.pMappedData) }; + bool mapped_here { false }; if (!mapped_data) { VkResult res = vmaMapMemory( m_vk.allocator, upload_buffer.allocation, (void **)&mapped_data); assert(res == VK_SUCCESS); + mapped_here = true; } - defer({ - if (info.pMappedData == nullptr) { - vmaUnmapMemory(m_vk.allocator, upload_buffer.allocation); - } - }); memcpy(mapped_data, data, data_size); @@ -1175,6 +1172,9 @@ auto VulkanRenderer::create_image(void const *data, VkExtent3D size, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); }); + if (mapped_here) { + vmaUnmapMemory(m_vk.allocator, upload_buffer.allocation); + } destroy_buffer(upload_buffer); return new_image; @@ -1249,15 +1249,12 @@ auto VulkanRenderer::upload_mesh( vmaGetAllocationInfo(m_vk.allocator, staging.allocation, &info); void *data = info.pMappedData; + bool mapped_here { false }; if (!data) { VkResult res = vmaMapMemory(m_vk.allocator, staging.allocation, &data); assert(res == VK_SUCCESS); + mapped_here = true; } - defer({ - if (info.pMappedData == nullptr) { - vmaUnmapMemory(m_vk.allocator, staging.allocation); - } - }); memcpy(data, vertices.data(), vertex_buffer_size); memcpy(reinterpret_cast( @@ -1282,6 +1279,9 @@ auto VulkanRenderer::upload_mesh( &index_copy); }); + if (mapped_here) { + vmaUnmapMemory(m_vk.allocator, staging.allocation); + } destroy_buffer(staging); return new_surface; diff --git a/thirdparty/smath b/thirdparty/smath index a5d6692..1a42238 160000 --- a/thirdparty/smath +++ b/thirdparty/smath @@ -1 +1 @@ -Subproject commit a5d669235e81a05e80ceb41840a417ca146692c4 +Subproject commit 1a42238a41f84373a567c777baaf7ad18c860162