Skip to content

Commit

Permalink
#5584: Purge any shaders that have not been used the last frame, to p…
Browse files Browse the repository at this point in the history
…revent introducing a long-running memory leak.

Re-using the CamRenderer container memory reduces the time needed to render 100 frames from 8.7 to 7.7 seconds.
  • Loading branch information
codereader committed Nov 1, 2021
1 parent 8dc3125 commit 1eee48d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions libs/render/CamRenderer.h
Expand Up @@ -104,9 +104,17 @@ class CamRenderer :
{
// Keep the shader map intact, but clear the renderables vectors,
// so that we don't have to re-allocate the whole memory every frame
for (auto& pair : _litRenderables)
// Purge the ones that have not been used in this render round
for (auto i = _litRenderables.begin(); i != _litRenderables.end();)
{
pair.second.clear();
if (i->second.empty())
{
// This shader has not been used at all in the last frame, free the memory
_litRenderables.erase(i++);
continue;
}

(i++)->second.clear();
}

_sceneLights.clear();
Expand Down

0 comments on commit 1eee48d

Please sign in to comment.