diff options
author | Jeroen Bakker <jeroen@blender.org> | 2021-10-05 11:34:05 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2021-10-05 11:36:45 +0300 |
commit | 9824df49c0694a67158598f232a55a80fe4ba2ce (patch) | |
tree | ecca7856e3657426f0ab277cc5268f17def56187 /source/blender | |
parent | 7a66a9f22e6614b88ec262cceefa196906dd434d (diff) |
Fix memory leak when running test cases.
Issue is that test cases re-uses draw manager. The new
`DRWRegisteredDrawEngine` struct is only freed when a
valid opengl context was found. what isn't the case
when running test cases.
Also made sure that re-using draw manager would use re-inited
values.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/draw/intern/draw_manager.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 7a41142b177..8d8375556c7 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -2928,8 +2928,27 @@ void DRW_engines_register(void) } } +static void drw_registered_engines_free(void) +{ + DRWRegisteredDrawEngine *next; + for (DRWRegisteredDrawEngine *type = g_registered_engines.engines.first; type; type = next) { + next = type->next; + BLI_remlink(&R_engines, type); + + if (type->draw_engine->engine_free) { + type->draw_engine->engine_free(); + } + MEM_freeN(type); + } + + BLI_listbase_clear(&g_registered_engines.engines); + g_registered_engines.len = 0; +} + void DRW_engines_free(void) { + drw_registered_engines_free(); + if (DST.gl_context == NULL) { /* Nothing has been setup. Nothing to clear. * Otherwise, DRW_opengl_context_enable can @@ -2948,17 +2967,6 @@ void DRW_engines_free(void) DRW_stats_free(); DRW_globals_free(); - DRWRegisteredDrawEngine *next; - for (DRWRegisteredDrawEngine *type = g_registered_engines.engines.first; type; type = next) { - next = type->next; - BLI_remlink(&R_engines, type); - - if (type->draw_engine->engine_free) { - type->draw_engine->engine_free(); - } - MEM_freeN(type); - } - DRW_UBO_FREE_SAFE(G_draw.block_ubo); DRW_UBO_FREE_SAFE(G_draw.view_ubo); DRW_TEXTURE_FREE_SAFE(G_draw.ramp); |