From cd3fade2aaf74d1c3db345c13bd0122dc45d372f Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 15 Mar 2021 16:11:12 +0100 Subject: Fix Cycles rendering crash on OpenBSD Static initialization order was not guaranteed to be correct for node base types. Now wrap all initialization in accessor functions to ensure the order is correct. Did not cause any known bug on Linux/macOS/Windows, but showed up on this platform. --- intern/cycles/graph/node_type.h | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'intern/cycles/graph/node_type.h') diff --git a/intern/cycles/graph/node_type.h b/intern/cycles/graph/node_type.h index 3b9b3007099..2a741d9b06f 100644 --- a/intern/cycles/graph/node_type.h +++ b/intern/cycles/graph/node_type.h @@ -87,7 +87,7 @@ struct SocketType { int struct_offset; const void *default_value; const NodeEnum *enum_values; - const NodeType **node_type; + const NodeType *node_type; int flags; ustring ui_name; SocketModifiedFlags modified_flag_bit; @@ -115,7 +115,7 @@ struct NodeType { int struct_offset, const void *default_value, const NodeEnum *enum_values = NULL, - const NodeType **node_type = NULL, + const NodeType *node_type = NULL, int flags = 0, int extra_flags = 0); void register_output(ustring name, ustring ui_name, SocketType::Type type); @@ -140,27 +140,38 @@ struct NodeType { static unordered_map &types(); }; -/* Node Definition Macros */ +/* Node Definition Macros + * + * Node we use accessor to get node types to ensure correct static + * initialization order. */ #define NODE_DECLARE \ + static const NodeType *get_node_type(); \ template static const NodeType *register_type(); \ - static Node *create(const NodeType *type); \ - static const NodeType *node_type; + static Node *create(const NodeType *type); #define NODE_DEFINE(structname) \ - const NodeType *structname::node_type = structname::register_type(); \ Node *structname::create(const NodeType *) \ { \ return new structname(); \ } \ + const NodeType *structname::get_node_type() \ + { \ + static const NodeType *node_type = register_type(); \ + return node_type; \ + } \ template const NodeType *structname::register_type() #define NODE_ABSTRACT_DECLARE \ template static const NodeType *register_base_type(); \ - static const NodeType *node_base_type; + static const NodeType *get_node_base_type(); #define NODE_ABSTRACT_DEFINE(structname) \ - const NodeType *structname::node_base_type = structname::register_base_type(); \ + const NodeType *structname::get_node_base_type() \ + { \ + static const NodeType *node_base_type = register_base_type(); \ + return node_base_type; \ + } \ template const NodeType *structname::register_base_type() /* Sock Definition Macros */ -- cgit v1.2.3