From 776a748e051503e40d250e5cfe4ac508b61613cf Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Mon, 9 Dec 2024 14:51:52 -0800 Subject: [PATCH] fix a ResourceList<> "soft" leak when destroying a material A ResourceList<> object was leaked when destroying a material until the Engine was shut down. This could however grow unbounded if churning through Materials. What was actually leaked was entries in the hashmap linking a material to its material instance list. BUGS=[383158161] --- filament/src/details/Engine.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/filament/src/details/Engine.cpp b/filament/src/details/Engine.cpp index a9c39de272d..576e0e081a8 100644 --- a/filament/src/details/Engine.cpp +++ b/filament/src/details/Engine.cpp @@ -1159,8 +1159,13 @@ bool FEngine::destroy(const FMaterial* ptr) { if (!ASSERT_PRECONDITION_NON_FATAL(pos->second.empty(), "destroying material \"%s\" but %u instances still alive", ptr->getName().c_str(), (*pos).second.size())) { - return false; + // We return true here, because the material has been destroyed. However, this + // leaks this material's ResourceList until the engine + // is shut down. Note that it's still possible for the MaterialInstances to be + // destroyed manually. + return true; } + mMaterialInstances.erase(pos); } } return success;