fix crash on exit

This commit is contained in:
niki
2022-06-16 02:25:55 +02:00
parent b5ba2b65b5
commit efdc2b8ee2
2 changed files with 11 additions and 42 deletions
+9 -34
View File
@@ -6,6 +6,7 @@
#include "Shader.h"
#include "graphics/Texture.h"
#include "Vulkan.h"
#include "common/version.h"
#include <vector>
#include <cstring>
@@ -43,24 +44,6 @@ namespace love {
const int MAX_FRAMES_IN_FLIGHT = 2;
static std::vector<char> 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<char> 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<love::graphics::Buffer::DataDeclaration>& 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<char>& code) {
VkShaderModuleCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
createInfo.codeSize = code.size();
createInfo.pCode = reinterpret_cast<const uint32_t*>(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*>(love::graphics::vulkan::Shader::standardShaders[Shader::STANDARD_DEFAULT]);
auto shaderStages = shader->getShaderStages();
+2 -8
View File
@@ -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> 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;