From 3d6c86d04e92008a52e5195944b42d8df4948ff6 Mon Sep 17 00:00:00 2001 From: Benau Date: Sun, 17 Apr 2022 14:42:36 +0800 Subject: [PATCH] Clean up properly in case constructor throws --- lib/graphics_engine/src/ge_vulkan_driver.cpp | 25 +++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/graphics_engine/src/ge_vulkan_driver.cpp b/lib/graphics_engine/src/ge_vulkan_driver.cpp index a0ec9f989..adcd5546a 100644 --- a/lib/graphics_engine/src/ge_vulkan_driver.cpp +++ b/lib/graphics_engine/src/ge_vulkan_driver.cpp @@ -539,15 +539,24 @@ GEVulkanDriver::GEVulkanDriver(const SIrrlichtCreationParameters& params, os::Printer::log("Vulkan driver version", getDriverVersionString().c_str()); for (const char* ext : m_device_extensions) os::Printer::log("Vulkan enabled extension", ext); - GEVulkanCommandLoader::init(this); - createCommandBuffers(); - GEVulkanShaderManager::init(this); - // For GEVulkanDynamicBuffer - GE::setVideoDriver(this); - GEVulkan2dRenderer::init(this); - createUnicolorTextures(); - GEVulkanFeatures::printStats(); + try + { + GEVulkanCommandLoader::init(this); + createCommandBuffers(); + + GEVulkanShaderManager::init(this); + // For GEVulkanDynamicBuffer + GE::setVideoDriver(this); + GEVulkan2dRenderer::init(this); + createUnicolorTextures(); + GEVulkanFeatures::printStats(); + } + catch (std::exception& e) + { + destroyVulkan(); + throw std::runtime_error("GEVulkanDriver constructor failed"); + } } // GEVulkanDriver // ----------------------------------------------------------------------------