From b8278db0cd73676c74fade8d30ec48f660b0c41d Mon Sep 17 00:00:00 2001 From: quou Date: Thu, 19 Dec 2024 19:35:36 +1100 Subject: properly destroy objects on device destruction --- video.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/video.cpp b/video.cpp index c274e65..03b822b 100644 --- a/video.cpp +++ b/video.cpp @@ -242,6 +242,7 @@ struct Context_Vk : public Context { void begin_record(Device_Vk* dev); Context_Vk& acquire(Device_Vk* dev); void release(); + void destroy(Device_Vk* dev); }; struct Texture_Vk : public Texture { @@ -631,9 +632,18 @@ void Device_Vk::init_internal() { } void Device_Vk::deinit_internal() { + int i; + vkDeviceWaitIdle(dev); swapchain.destroy(this); deinit_swap_cap(this, &swap_cap); app_destroy_vk_surface(app, inst, surf); + for (auto& i : rpo_cache) + i.second.destroy(this); + for (i = 0; i < max_contexts; i++) { + auto& context = contexts[i]; + if (context.state & context_state_init) + context.destroy(this); + } vkDestroyDevice(dev, &ac); #ifdef DEBUG destroy_dmesg( @@ -1140,6 +1150,13 @@ void Context_Vk::release() { state |= context_state_avail; } +void Context_Vk::destroy(Device_Vk* dev) { + state &= ~context_state_init; + vkDestroyCommandPool(dev->dev, pool, &dev->ac); + vkDestroySemaphore(dev->dev, semaphore, &dev->ac); + vkDestroyFence(dev->dev, fence, &dev->ac); +} + Context& Device::acquire() { Device_Vk* vk = (Device_Vk*)this; int i; -- cgit v1.2.3-54-g00ecf