From efdc2b8ee254edaf76aa58ccbc991697cc13f343 Mon Sep 17 00:00:00 2001 From: niki Date: Thu, 16 Jun 2022 02:25:55 +0200 Subject: [PATCH] fix crash on exit --- src/modules/graphics/vulkan/Graphics.cpp | 43 +++++------------------- src/modules/graphics/vulkan/Graphics.h | 10 ++---- 2 files changed, 11 insertions(+), 42 deletions(-) diff --git a/src/modules/graphics/vulkan/Graphics.cpp b/src/modules/graphics/vulkan/Graphics.cpp index 5b6e05cda..273d4e497 100644 --- a/src/modules/graphics/vulkan/Graphics.cpp +++ b/src/modules/graphics/vulkan/Graphics.cpp @@ -6,6 +6,7 @@ #include "Shader.h" #include "graphics/Texture.h" #include "Vulkan.h" +#include "common/version.h" #include #include @@ -43,24 +44,6 @@ namespace love { const int MAX_FRAMES_IN_FLIGHT = 2; - static std::vector readFile(const std::string& filename) { - std::ifstream file(filename, std::ios::ate | std::ios::binary); - - if (!file.is_open()) { - throw std::runtime_error("failed to open file!"); - } - - size_t fileSize = (size_t)file.tellg(); - std::vector buffer(fileSize); - - file.seekg(0); - file.read(buffer.data(), fileSize); - - file.close(); - - return buffer; - } - const char* Graphics::getName() const { return "love.graphics.vulkan"; } @@ -68,6 +51,13 @@ namespace love { Graphics::Graphics() { } + Graphics::~Graphics() { + // FIXME: most resources that are allocated dynamically need proper cleanup. + batchedDrawState.vb[0] = nullptr; + batchedDrawState.vb[1] = nullptr; + batchedDrawState.indexBuffer = nullptr; + } + // START OVERRIDEN FUNCTIONS love::graphics::Buffer* Graphics::newBuffer(const love::graphics::Buffer::Settings& settings, const std::vector& format, const void* data, size_t size, size_t arraylength) { @@ -456,7 +446,7 @@ namespace love { appInfo.pApplicationName = "LOVE"; appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0); //todo, get this version from somewhere else? appInfo.pEngineName = "LOVE Engine"; - appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0); //todo, same as above + appInfo.engineVersion = VK_MAKE_VERSION(VERSION_MAJOR, VERSION_MINOR, VERSION_REV); appInfo.apiVersion = VK_API_VERSION_1_0; VkInstanceCreateInfo createInfo{}; @@ -902,20 +892,6 @@ namespace love { } } - static VkShaderModule createShaderModule(VkDevice device, const std::vector& code) { - VkShaderModuleCreateInfo createInfo{}; - createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; - createInfo.codeSize = code.size(); - createInfo.pCode = reinterpret_cast(code.data()); - - VkShaderModule shaderModule; - if (vkCreateShaderModule(device, &createInfo, nullptr, &shaderModule) != VK_SUCCESS) { - throw love::Exception("failed to create shader module"); - } - - return shaderModule; - } - void Graphics::createDefaultShaders() { for (int i = 0; i < Shader::STANDARD_MAX_ENUM; i++) { auto stype = (Shader::StandardShader)i; @@ -1113,7 +1089,6 @@ namespace love { } VkPipeline Graphics::createGraphicsPipeline(GraphicsPipelineConfiguration configuration) { - auto shader = reinterpret_cast(love::graphics::vulkan::Shader::standardShaders[Shader::STANDARD_DEFAULT]); auto shaderStages = shader->getShaderStages(); diff --git a/src/modules/graphics/vulkan/Graphics.h b/src/modules/graphics/vulkan/Graphics.h index cf212d704..bdf48bf60 100644 --- a/src/modules/graphics/vulkan/Graphics.h +++ b/src/modules/graphics/vulkan/Graphics.h @@ -23,7 +23,7 @@ namespace love { public: Graphics(); - virtual ~Graphics() = default; + virtual ~Graphics(); const char* getName() const override; @@ -132,11 +132,7 @@ namespace love { std::vector batchedDrawBuffers; void updatedBatchedDrawBuffers(); - - void createVulkanVertexFormat( - VertexAttributes vertexAttributes, - bool& useConstantVertexColor, - GraphicsPipelineConfiguration& configuration); + void createVulkanVertexFormat(VertexAttributes vertexAttributes, bool& useConstantVertexColor, GraphicsPipelineConfiguration& configuration); // vulkan specific member functions and variables @@ -185,11 +181,9 @@ namespace love { void cleanup(); void cleanupSwapChain(); void recreateSwapChain(); - void startRecordingGraphicsCommands(); void endRecordingGraphicsCommands(); void ensureGraphicsPipelineConfiguration(GraphicsPipelineConfiguration); - void prepareDraw(uint32_t currentImage); VkInstance instance;