From dfa326ef55ee7c973afef6527b42844e7179a0ff Mon Sep 17 00:00:00 2001 From: David Sullivan <62087657+sullyscience@users.noreply.github.com> Date: Thu, 14 Mar 2024 16:07:44 -0400 Subject: [PATCH] Fix: Address mobile resource leaks in render Update render_forward_mobile destructor to include instance buffers. Update render_scene_buffers_rd cleanup to include weight buffers / blur textures. --- .../renderer_rd/forward_mobile/render_forward_mobile.cpp | 5 +++++ .../renderer_rd/storage_rd/render_scene_buffers_rd.cpp | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp index ac93aca6bb0..2f307c62f35 100644 --- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp +++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp @@ -2835,6 +2835,11 @@ RenderForwardMobile::~RenderForwardMobile() { for (const RID &rid : scene_state.uniform_buffers) { RD::get_singleton()->free(rid); } + for (uint32_t i = 0; i < RENDER_LIST_MAX; i++) { + if (scene_state.instance_buffer[i].is_valid()) { + RD::get_singleton()->free(scene_state.instance_buffer[i]); + } + } RD::get_singleton()->free(scene_state.lightmap_buffer); RD::get_singleton()->free(scene_state.lightmap_capture_buffer); memdelete_arr(scene_state.lightmap_captures); diff --git a/servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.cpp b/servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.cpp index 8dc74820e22..c5d74d395f2 100644 --- a/servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.cpp +++ b/servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.cpp @@ -128,6 +128,13 @@ void RenderSceneBuffersRD::cleanup() { free_named_texture(E.value); } named_textures.clear(); + + // Clear weight_buffer / blur textures. + for (const WeightBuffers &weight_buffer : weight_buffers) { + if (weight_buffer.weight.is_valid()) { + RD::get_singleton()->free(weight_buffer.weight); + } + } } void RenderSceneBuffersRD::configure(const RenderSceneBuffersConfiguration *p_config) {