From bce23aa0f51e96db6ff162e83b43b8ae7ffd79c1 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Thu, 24 Aug 2023 10:23:21 +0200 Subject: [PATCH] Fix: Crash On Exit When Using Vulkan Vulkan device was deallocated, but when destroying the GHOST context the GPU context is reactivated and want to allocate buffers lazilly. This is solved by de-initializing the device on platform exit, resetting buffer pointers so double free can be detected. Pull Request: https://projects.blender.org/blender/blender/pulls/111462 --- source/blender/gpu/vulkan/vk_backend.cc | 11 +++++------ source/blender/gpu/vulkan/vk_buffer.cc | 6 +++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/source/blender/gpu/vulkan/vk_backend.cc b/source/blender/gpu/vulkan/vk_backend.cc index 81fb7b75e0d..788acb7297b 100644 --- a/source/blender/gpu/vulkan/vk_backend.cc +++ b/source/blender/gpu/vulkan/vk_backend.cc @@ -90,15 +90,14 @@ void VKBackend::detect_workarounds(VKDevice &device) void VKBackend::platform_exit() { GPG.clear(); -} - -void VKBackend::delete_resources() -{ - if (device_.is_initialized()) { - device_.deinit(); + VKDevice &device = VKBackend::get().device_; + if (device.is_initialized()) { + device.deinit(); } } +void VKBackend::delete_resources() {} + void VKBackend::samplers_update() {} void VKBackend::compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len) diff --git a/source/blender/gpu/vulkan/vk_buffer.cc b/source/blender/gpu/vulkan/vk_buffer.cc index bd6649aa575..d934d1e4384 100644 --- a/source/blender/gpu/vulkan/vk_buffer.cc +++ b/source/blender/gpu/vulkan/vk_buffer.cc @@ -14,7 +14,9 @@ namespace blender::gpu { VKBuffer::~VKBuffer() { - free(); + if (is_allocated()) { + free(); + } } bool VKBuffer::is_allocated() const @@ -144,6 +146,8 @@ bool VKBuffer::free() const VKDevice &device = VKBackend::get().device_get(); VmaAllocator allocator = device.mem_allocator_get(); vmaDestroyBuffer(allocator, vk_buffer_, allocation_); + allocation_ = VK_NULL_HANDLE; + vk_buffer_ = VK_NULL_HANDLE; return true; }