[Bf-blender-cvs] [f0adb87] blender-v2.78-release: Cycles: Fix static initialization order fiasco

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


Commit: f0adb875cf05cfc3364b28a6e7071c95c4af6ebc
Author: Sergey Sharybin
Date:   Mon Oct 24 13:43:55 2016 +0200
Branches: blender-v2.78-release
https://developer.blender.org/rBf0adb875cf05cfc3364b28a6e7071c95c4af6ebc

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