[Bf-blender-cvs] [cbf033c0551] master: Fix T86026: Crash Opening Cryptomatte File.

Jeroen Bakker noreply at git.blender.org
Mon Mar 8 08:53:02 CET 2021


Commit: cbf033c05519ffa977693a5f6845b476017af08b
Author: Jeroen Bakker
Date:   Mon Mar 8 08:47:22 2021 +0100
Branches: master
https://developer.blender.org/rBcbf033c05519ffa977693a5f6845b476017af08b

Fix T86026: Crash Opening Cryptomatte File.

But this time the root cause. Writing undo files is done in a separate
thread. This patch moved the updating of the matte_id when the user
actually changes the matte.

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

M	source/blender/blenkernel/intern/cryptomatte.cc
M	source/blender/blenkernel/intern/node.cc
M	source/blender/blenloader/intern/versioning_290.c
M	source/blender/makesdna/DNA_node_types.h

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

diff --git a/source/blender/blenkernel/intern/cryptomatte.cc b/source/blender/blenkernel/intern/cryptomatte.cc
index 3188656aa6b..6db471e830b 100644
--- a/source/blender/blenkernel/intern/cryptomatte.cc
+++ b/source/blender/blenkernel/intern/cryptomatte.cc
@@ -208,6 +208,17 @@ void BKE_cryptomatte_matte_id_to_entries(NodeCryptomatte *node_storage, const ch
   BLI_freelistN(&node_storage->entries);
   std::optional<CryptomatteSession> session = std::nullopt;
 
+  if (matte_id == nullptr) {
+    MEM_SAFE_FREE(node_storage->matte_id);
+    return;
+  }
+  /* Update the matte_id so the files can be opened in versions that don't
+   * use `CryptomatteEntry`. */
+  if (matte_id != node_storage->matte_id && STREQ(node_storage->matte_id, matte_id)) {
+    MEM_SAFE_FREE(node_storage->matte_id);
+    node_storage->matte_id = static_cast<char *>(MEM_dupallocN(matte_id));
+  }
+
   std::istringstream ss(matte_id);
   while (ss.good()) {
     CryptomatteEntry *entry = nullptr;
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 6b46ae3430b..c2ce52b1358 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -540,18 +540,11 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree)
       }
       else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_CRYPTOMATTE)) {
         NodeCryptomatte *nc = (NodeCryptomatte *)node->storage;
-        /* Update the matte_id so the files can be opened in versions that don't
-         * use `CryptomatteEntry`. */
-        MEM_SAFE_FREE(nc->matte_id);
-        nc->matte_id = BKE_cryptomatte_entries_to_matte_id(nc);
-        if (nc->matte_id) {
-          BLO_write_string(writer, nc->matte_id);
-        }
+        BLO_write_string(writer, nc->matte_id);
         LISTBASE_FOREACH (CryptomatteEntry *, entry, &nc->entries) {
           BLO_write_struct(writer, CryptomatteEntry, entry);
         }
         BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage);
-        MEM_SAFE_FREE(nc->matte_id);
       }
       else if (node->type == FN_NODE_INPUT_STRING) {
         NodeInputString *storage = (NodeInputString *)node->storage;
diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c
index 5c8e9da41c4..1aa1f0302e3 100644
--- a/source/blender/blenloader/intern/versioning_290.c
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -1469,7 +1469,6 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
                 continue;
               }
               BKE_cryptomatte_matte_id_to_entries(storage, storage->matte_id);
-              MEM_SAFE_FREE(storage->matte_id);
             }
           }
         }
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 8b0bc235861..82509599931 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1070,7 +1070,8 @@ typedef struct CryptomatteEntry {
 typedef struct NodeCryptomatte {
   float add[3];
   float remove[3];
-  char *matte_id DNA_DEPRECATED;
+  /* Stores `entries` as a string for opening in 2.80-2.91. */
+  char *matte_id;
   /* Contains `CryptomatteEntry`. */
   ListBase entries;
   int num_inputs;



More information about the Bf-blender-cvs mailing list