Archived
1
Fork 0

Properly free mesh buffers

This commit is contained in:
Joshua Goins 2018-10-16 09:01:14 -04:00
parent 354487878e
commit da6f245c79
3 changed files with 13 additions and 0 deletions

View file

@ -40,6 +40,7 @@ public:
uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties); uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
void fillMeshBuffers(Mesh* mesh); void fillMeshBuffers(Mesh* mesh);
void destroyMeshBuffers(Mesh* mesh);
VkInstance getInstance() const { VkInstance getInstance() const {
return instance_; return instance_;

View file

@ -79,6 +79,8 @@ int main(int, char*[]) {
renderer->render(world, target); renderer->render(world, target);
} }
renderer->destroyMeshBuffers(mesh);
renderer->destroyRenderTarget(target); renderer->destroyRenderTarget(target);
vkDestroySurfaceKHR(renderer->getInstance(), surface, nullptr); vkDestroySurfaceKHR(renderer->getInstance(), surface, nullptr);

View file

@ -347,6 +347,16 @@ void Renderer::fillMeshBuffers(Mesh* mesh) {
} }
} }
void Renderer::destroyMeshBuffers(Mesh* mesh) {
vkDeviceWaitIdle(device_);
vkFreeMemory(device_, mesh->indexMemory, nullptr);
vkDestroyBuffer(device_, mesh->indexBuffer, nullptr);
vkFreeMemory(device_, mesh->vertexMemory, nullptr);
vkDestroyBuffer(device_, mesh->vertexBuffer, nullptr);
}
void Renderer::createInstance() { void Renderer::createInstance() {
uint32_t layerCount = 0; uint32_t layerCount = 0;
vkEnumerateInstanceLayerProperties(&layerCount, nullptr); vkEnumerateInstanceLayerProperties(&layerCount, nullptr);