vulkan_blitter: Fix pool allocation double free.
This commit is contained in:
		| @@ -145,6 +145,11 @@ VkSemaphore BlitScreen::Draw(const Tegra::FramebufferConfig& framebuffer, | |||||||
|     // Finish any pending renderpass |     // Finish any pending renderpass | ||||||
|     scheduler.RequestOutsideRenderPassOperationContext(); |     scheduler.RequestOutsideRenderPassOperationContext(); | ||||||
|  |  | ||||||
|  |     if (const auto swapchain_images = swapchain.GetImageCount(); swapchain_images != image_count) { | ||||||
|  |         image_count = swapchain_images; | ||||||
|  |         Recreate(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     const std::size_t image_index = swapchain.GetImageIndex(); |     const std::size_t image_index = swapchain.GetImageIndex(); | ||||||
|  |  | ||||||
|     scheduler.Wait(resource_ticks[image_index]); |     scheduler.Wait(resource_ticks[image_index]); | ||||||
| @@ -448,15 +453,15 @@ vk::Framebuffer BlitScreen::CreateFramebuffer(const VkImageView& image_view, VkE | |||||||
|  |  | ||||||
| void BlitScreen::CreateStaticResources() { | void BlitScreen::CreateStaticResources() { | ||||||
|     CreateShaders(); |     CreateShaders(); | ||||||
|  |     CreateSampler(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void BlitScreen::CreateDynamicResources() { | ||||||
|     CreateSemaphores(); |     CreateSemaphores(); | ||||||
|     CreateDescriptorPool(); |     CreateDescriptorPool(); | ||||||
|     CreateDescriptorSetLayout(); |     CreateDescriptorSetLayout(); | ||||||
|     CreateDescriptorSets(); |     CreateDescriptorSets(); | ||||||
|     CreatePipelineLayout(); |     CreatePipelineLayout(); | ||||||
|     CreateSampler(); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void BlitScreen::CreateDynamicResources() { |  | ||||||
|     CreateRenderPass(); |     CreateRenderPass(); | ||||||
|     CreateFramebuffers(); |     CreateFramebuffers(); | ||||||
|     CreateGraphicsPipeline(); |     CreateGraphicsPipeline(); | ||||||
|   | |||||||
| @@ -109,7 +109,7 @@ private: | |||||||
|     MemoryAllocator& memory_allocator; |     MemoryAllocator& memory_allocator; | ||||||
|     Swapchain& swapchain; |     Swapchain& swapchain; | ||||||
|     Scheduler& scheduler; |     Scheduler& scheduler; | ||||||
|     const std::size_t image_count; |     std::size_t image_count; | ||||||
|     const ScreenInfo& screen_info; |     const ScreenInfo& screen_info; | ||||||
|  |  | ||||||
|     vk::ShaderModule vertex_shader; |     vk::ShaderModule vertex_shader; | ||||||
|   | |||||||
| @@ -519,9 +519,7 @@ public: | |||||||
|           dld{rhs.dld} {} |           dld{rhs.dld} {} | ||||||
|  |  | ||||||
|     /// Assign an allocation transfering ownership from another allocation. |     /// Assign an allocation transfering ownership from another allocation. | ||||||
|     /// Releases any previously held allocation. |  | ||||||
|     PoolAllocations& operator=(PoolAllocations&& rhs) noexcept { |     PoolAllocations& operator=(PoolAllocations&& rhs) noexcept { | ||||||
|         Release(); |  | ||||||
|         allocations = std::move(rhs.allocations); |         allocations = std::move(rhs.allocations); | ||||||
|         num = rhs.num; |         num = rhs.num; | ||||||
|         device = rhs.device; |         device = rhs.device; | ||||||
| @@ -530,11 +528,6 @@ public: | |||||||
|         return *this; |         return *this; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /// Destroys any held allocation. |  | ||||||
|     ~PoolAllocations() { |  | ||||||
|         Release(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /// Returns the number of allocations. |     /// Returns the number of allocations. | ||||||
|     std::size_t size() const noexcept { |     std::size_t size() const noexcept { | ||||||
|         return num; |         return num; | ||||||
| @@ -557,19 +550,6 @@ public: | |||||||
|     } |     } | ||||||
|  |  | ||||||
| private: | private: | ||||||
|     /// Destroys the held allocations if they exist. |  | ||||||
|     void Release() noexcept { |  | ||||||
|         if (!allocations) { |  | ||||||
|             return; |  | ||||||
|         } |  | ||||||
|         const Span<AllocationType> span(allocations.get(), num); |  | ||||||
|         const VkResult result = Free(device, pool, span, *dld); |  | ||||||
|         // There's no way to report errors from a destructor. |  | ||||||
|         if (result != VK_SUCCESS) { |  | ||||||
|             std::terminate(); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     std::unique_ptr<AllocationType[]> allocations; |     std::unique_ptr<AllocationType[]> allocations; | ||||||
|     std::size_t num = 0; |     std::size_t num = 0; | ||||||
|     VkDevice device = nullptr; |     VkDevice device = nullptr; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user