[Bf-blender-cvs] [d6e22109353] master: Fix inconsistent creation of `NodeTreeTypeUndefined` type of node tree

Bastien Montagne noreply at git.blender.org
Mon Nov 8 12:24:52 CET 2021


Commit: d6e22109353cf9920284f3f84dee9b8cfd125669
Author: Bastien Montagne
Date:   Mon Nov 8 11:51:54 2021 +0100
Branches: master
https://developer.blender.org/rBd6e22109353cf9920284f3f84dee9b8cfd125669

Fix inconsistent creation of `NodeTreeTypeUndefined` type of node tree

Currently, when creating a new node tree ID, its `typeinfo` is set to
`NodeTreeTypeUndefined`, but its `type` enum value is left to `0`,
aka `NTREE_SHADER`.

This patch adds a new `NTREE_UNDIFINED` value, and use it for
`NodeTreeTypeUndefined` types of node trees.

NOTE: While it is not clear whether that actually fixes issues currently,
quite a bit of code still relies on the value of `type`, so think it
makes sense to sanitize this.

NOTE: Would have been ideal to reserve `0` value to undefined type,
but at this point this is not possible anymore, so chose to use `-2` instead.

Reviewed By: JacquesLucke

Differential Revision: https://developer.blender.org/D13123

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

M	source/blender/blenkernel/intern/node.cc
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesrna/intern/rna_nodetree.c

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

diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 60a9ce48a0a..eb2b125e7e6 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -1160,15 +1160,15 @@ static void ntree_set_typeinfo(bNodeTree *ntree, bNodeTreeType *typeinfo)
 {
   if (typeinfo) {
     ntree->typeinfo = typeinfo;
-
-    /* deprecated integer type */
-    ntree->type = typeinfo->type;
   }
   else {
     ntree->typeinfo = &NodeTreeTypeUndefined;
 
     ntree->init &= ~NTREE_TYPE_INIT;
   }
+
+  /* Deprecated integer type. */
+  ntree->type = ntree->typeinfo->type;
 }
 
 static void node_set_typeinfo(const struct bContext *C,
@@ -5533,6 +5533,7 @@ static void register_undefined_types()
    * they are just used as placeholders in case the actual types are not registered.
    */
 
+  NodeTreeTypeUndefined.type = NTREE_UNDEFINED;
   strcpy(NodeTreeTypeUndefined.idname, "NodeTreeUndefined");
   strcpy(NodeTreeTypeUndefined.ui_name, N_("Undefined"));
   strcpy(NodeTreeTypeUndefined.ui_description, N_("Undefined Node Tree Type"));
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 79287885dec..cfe34d83586 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -577,7 +577,9 @@ typedef struct bNodeTree {
 } bNodeTree;
 
 /* ntree->type, index */
-#define NTREE_CUSTOM -1 /* for dynamically registered custom types */
+
+#define NTREE_UNDEFINED -2 /* Represents #NodeTreeTypeUndefined type. */
+#define NTREE_CUSTOM -1    /* for dynamically registered custom types */
 #define NTREE_SHADER 0
 #define NTREE_COMPOSIT 1
 #define NTREE_TEXTURE 2
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 01889a1b0a9..53b3f07dbbc 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -12753,6 +12753,11 @@ static void rna_def_nodetree(BlenderRNA *brna)
   PropertyRNA *parm;
 
   static const EnumPropertyItem static_type_items[] = {
+      {NTREE_UNDEFINED,
+       "UNDEFINED",
+       ICON_QUESTION,
+       "Undefined",
+       "Undefined type of nodes (can happen e.g. when a linked node tree goes missing)"},
       {NTREE_SHADER, "SHADER", ICON_MATERIAL, "Shader", "Shader nodes"},
       {NTREE_TEXTURE, "TEXTURE", ICON_TEXTURE, "Texture", "Texture nodes"},
       {NTREE_COMPOSIT, "COMPOSITING", ICON_RENDERLAYERS, "Compositing", "Compositing nodes"},



More information about the Bf-blender-cvs mailing list