From ec17b45034fbc9278bb42ea574bdaf2b8a6857e3 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Fri, 24 Jul 2020 12:38:04 +0200 Subject: Depsgraph: use construct on first use idiom for graph registry This is necessary to avoid false positive memory leaks. --- source/blender/depsgraph/intern/depsgraph_registry.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'source/blender/depsgraph') diff --git a/source/blender/depsgraph/intern/depsgraph_registry.cc b/source/blender/depsgraph/intern/depsgraph_registry.cc index c9d03e47ded..623702ee3ae 100644 --- a/source/blender/depsgraph/intern/depsgraph_registry.cc +++ b/source/blender/depsgraph/intern/depsgraph_registry.cc @@ -30,29 +30,35 @@ namespace blender { namespace deg { -static RawMap
> g_graph_registry; +using GraphRegistry = Map
>; +static GraphRegistry &get_graph_registry() +{ + static GraphRegistry graph_registry; + return graph_registry; +} void register_graph(Depsgraph *depsgraph) { Main *bmain = depsgraph->bmain; - g_graph_registry.lookup_or_add_default(bmain).add_new(depsgraph); + get_graph_registry().lookup_or_add_default(bmain).add_new(depsgraph); } void unregister_graph(Depsgraph *depsgraph) { Main *bmain = depsgraph->bmain; - RawVectorSet &graphs = g_graph_registry.lookup(bmain); + GraphRegistry &graph_registry = get_graph_registry(); + VectorSet &graphs = graph_registry.lookup(bmain); graphs.remove(depsgraph); // If this was the last depsgraph associated with the main, remove the main entry as well. if (graphs.is_empty()) { - g_graph_registry.remove(bmain); + graph_registry.remove(bmain); } } Span get_all_registered_graphs(Main *bmain) { - RawVectorSet *graphs = g_graph_registry.lookup_ptr(bmain); + VectorSet *graphs = get_graph_registry().lookup_ptr(bmain); if (graphs != nullptr) { return *graphs; } -- cgit v1.2.3