Browse Source

vulkan: fix some more memory leaks

niki 3 years ago
parent
commit
c5327bfc4f

+ 5 - 5
src/modules/graphics/vulkan/Graphics.cpp

@@ -1181,7 +1181,7 @@ namespace love {
 				}
 
 				if (texture == nullptr) {
-					setTexture(standardTexture);
+					setTexture(standardTexture.get());
 				}
 				else {
 					setTexture(texture);
@@ -1402,7 +1402,7 @@ namespace love {
 
 			void Graphics::createDefaultTexture() {
 				Texture::Settings settings;
-				standardTexture = newTexture(settings);
+				standardTexture.reset((Texture*)newTexture(settings));
 			}
 
 			void Graphics::createQuadIndexBuffer() {
@@ -1410,7 +1410,7 @@ namespace love {
 					return;
 
 				size_t size = sizeof(uint16) * getIndexCount(TRIANGLEINDEX_QUADS, LOVE_UINT16_MAX);
-				quadIndexBuffer = static_cast<StreamBuffer*>(newStreamBuffer(BUFFERUSAGE_INDEX, size));
+				quadIndexBuffer.reset((StreamBuffer*)newStreamBuffer(BUFFERUSAGE_INDEX, size));
 				auto map = quadIndexBuffer->map(size);
 				fillIndices(TRIANGLEINDEX_QUADS, 0, LOVE_UINT16_MAX, (uint16*)map.data);
 				quadIndexBuffer->unmap(size);
@@ -1460,14 +1460,13 @@ namespace love {
 
 				cleanupSwapChain();
 
+				batchedDrawBuffers.clear();
 				for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
 					vkDestroySemaphore(device, renderFinishedSemaphores[i], nullptr);
 					vkDestroySemaphore(device, imageAvailableSemaphores[i], nullptr);
 					vkDestroyFence(device, inFlightFences[i], nullptr);
 				}
 
-				vkDestroyDescriptorPool(device, descriptorPool, nullptr);
-
 				vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
 				vkDestroyCommandPool(device, commandPool, nullptr);
 				vkDestroyDevice(device, nullptr);
@@ -1478,6 +1477,7 @@ namespace love {
 			void Graphics::cleanupSwapChain() {
 				std::cout << "cleanupSwapChain ";
 
+				vkDestroyDescriptorPool(device, descriptorPool, nullptr);
 				for (size_t i = 0; i < swapChainFramBuffers.size(); i++) {
 					vkDestroyFramebuffer(device, swapChainFramBuffers[i], nullptr);
 				}

+ 2 - 2
src/modules/graphics/vulkan/Graphics.h

@@ -204,11 +204,11 @@ namespace love {
 				uint32_t imageIndex = 0;
 				bool framebufferResized = false;
 				VmaAllocator vmaAllocator = VK_NULL_HANDLE;
-				graphics::Texture* standardTexture = nullptr;
+				std::unique_ptr<Texture> standardTexture = nullptr;
+				std::unique_ptr<StreamBuffer> quadIndexBuffer = nullptr;
 				// we need an array of draw buffers, since the frames are being rendered asynchronously
 				// and we can't (or shouldn't) update the contents of the buffers while they're still in flight / being rendered.
 				std::vector<BatchedDrawBuffers> batchedDrawBuffers;
-				StreamBuffer* quadIndexBuffer = nullptr;
 				graphics::Texture* currentTexture = nullptr;
 				std::vector<std::pair<graphics::Shader::BuiltinUniformData, graphics::StreamBuffer*>> uniformBufferMap;
 				std::vector<std::pair<DecriptorSetConfiguration, std::vector<VkDescriptorSet>>> descriptorSetsMap;

+ 2 - 0
src/modules/graphics/vulkan/ShaderStage.cpp

@@ -205,6 +205,8 @@ namespace love {
 				if (vkCreateShaderModule(device, &createInfo, nullptr, &shaderModule) != VK_SUCCESS) {
 					throw love::Exception("failed to create shader module");
 				}
+
+				return true;
 			}
 
 			void ShaderStage::unloadVolatile() {

+ 2 - 0
src/modules/graphics/vulkan/Texture.cpp

@@ -61,6 +61,8 @@ namespace love {
 				}
 				createTextureImageView();
 				createTextureSampler();
+
+				return true;
 			}
 
 			void Texture::unloadVolatile() {