[Bf-blender-cvs] [cde18cf] master: Cycles: Fix static initialization order fiasco

Sergey Sharybin noreply at git.blender.org
Mon Oct 24 13:47:43 CEST 2016


Commit: cde18cf3b349a3a4d3b435fd3f76e5304ee446d6
Author: Sergey Sharybin
Date:   Mon Oct 24 13:43:55 2016 +0200
Branches: master
https://developer.blender.org/rBcde18cf3b349a3a4d3b435fd3f76e5304ee446d6

Cycles: Fix static initialization order fiasco

Initialization order of global stats and node types was not strictly
defined and it was possible to have node types initialized first and
stats after that. This will zero out memory which was allocated from
the statistics causing assert failure when de-initializing node types.

===================================================================

M	intern/cycles/util/util_guarded_allocator.cpp
M	intern/cycles/util/util_stats.h

===================================================================

diff --git a/intern/cycles/util/util_guarded_allocator.cpp b/intern/cycles/util/util_guarded_allocator.cpp
index 8de6e25..615ac95 100644
--- a/intern/cycles/util/util_guarded_allocator.cpp
+++ b/intern/cycles/util/util_guarded_allocator.cpp
@@ -19,7 +19,7 @@
 
 CCL_NAMESPACE_BEGIN
 
-static Stats global_stats;
+static Stats global_stats(Stats::static_init);
 
 /* Internal API. */
 
diff --git a/intern/cycles/util/util_stats.h b/intern/cycles/util/util_stats.h
index ce27067..b970b01 100644
--- a/intern/cycles/util/util_stats.h
+++ b/intern/cycles/util/util_stats.h
@@ -23,7 +23,10 @@ CCL_NAMESPACE_BEGIN
 
 class Stats {
 public:
+	enum static_init_t { static_init = 0 };
+
 	Stats() : mem_used(0), mem_peak(0) {}
+	explicit Stats(static_init_t) {}
 
 	void mem_alloc(size_t size) {
 		atomic_add_z(&mem_used, size);




More information about the Bf-blender-cvs mailing list