[Bf-blender-cvs] [e46687c3aac] master: Address to some extent issues with invalid embedded IDs in existing files.

Bastien Montagne noreply at git.blender.org
Tue Sep 6 18:01:58 CEST 2022


Commit: e46687c3aacfd69bde83187233e73a8cc6fa5d8d
Author: Bastien Montagne
Date:   Tue Sep 6 17:22:10 2022 +0200
Branches: master
https://developer.blender.org/rBe46687c3aacfd69bde83187233e73a8cc6fa5d8d

Address to some extent issues with invalid embedded IDs in existing files.

Many existing .blend files (including startup ones) seem to have invalid
embedded IDs (they are not properly tagged with `LIB_EMBEDDED_DATA`).

We cannot `do_version` this so just fix it on the fly when detecting the
issue. User then need to re-save these files.

We also need to update some release files (default factory startup is
OK, but e.g. the VSE template one is not).

Keeping the assert is important here, as such missing flag is a critical
data corruption that can potentially have many serious consequences
throughout the ID management code.

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

M	source/blender/blenkernel/intern/collection.c
M	source/blender/blenkernel/intern/node.cc

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

diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index e77525d0cb7..9795dafa6b9 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -7,6 +7,8 @@
 /* Allow using deprecated functionality for .blend file I/O. */
 #define DNA_DEPRECATED_ALLOW
 
+#include "CLG_log.h"
+
 #include <string.h>
 
 #include "BLI_blenlib.h"
@@ -46,6 +48,8 @@
 
 #include "BLO_read_write.h"
 
+static CLG_LogRef LOG = {"bke.collection"};
+
 /* -------------------------------------------------------------------- */
 /** \name Prototypes
  * \{ */
@@ -232,6 +236,20 @@ void BKE_collection_blend_read_data(BlendDataReader *reader, Collection *collect
   /* Special case for this pointer, do not rely on regular `lib_link` process here. Avoids needs
    * for do_versioning, and ensures coherence of data in any case. */
   BLI_assert((collection->id.flag & LIB_EMBEDDED_DATA) != 0 || owner_id == NULL);
+  if (owner_id != NULL && (collection->id.flag & LIB_EMBEDDED_DATA) == 0) {
+    /* This is unfortunate, but currently a lot of existing files (including startup ones) have
+     * missing `LIB_EMBEDDED_DATA` flag.
+     *
+     * NOTE: Using do_version is not a solution here, since this code will be called before any
+     * do_version takes place. Keeping it here also ensures future (or unknown existing) similar
+     * bugs won't go easily unoticed. */
+    CLOG_WARN(&LOG,
+              "Fixing root node tree '%s' owned by '%s' missing EMBEDDED tag, please consider "
+              "re-saving your (startup) file",
+              collection->id.name,
+              owner_id->name);
+    collection->id.flag |= LIB_EMBEDDED_DATA;
+  }
   collection->owner_id = owner_id;
 
   BLO_read_list(reader, &collection->gobject);
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index e648d9577d2..97512c9a84e 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -654,6 +654,20 @@ void ntreeBlendReadData(BlendDataReader *reader, ID *owner_id, bNodeTree *ntree)
   /* Special case for this pointer, do not rely on regular `lib_link` process here. Avoids needs
    * for do_versioning, and ensures coherence of data in any case. */
   BLI_assert((ntree->id.flag & LIB_EMBEDDED_DATA) != 0 || owner_id == nullptr);
+  if (owner_id != nullptr && (ntree->id.flag & LIB_EMBEDDED_DATA) == 0) {
+    /* This is unfortunate, but currently a lot of existing files (including startup ones) have
+     * missing `LIB_EMBEDDED_DATA` flag.
+     *
+     * NOTE: Using do_version is not a solution here, since this code will be called before any
+     * do_version takes place. Keeping it here also ensures future (or unknown existing) similar
+     * bugs won't go easily unoticed. */
+    CLOG_WARN(&LOG,
+              "Fixing root node tree '%s' owned by '%s' missing EMBEDDED tag, please consider "
+              "re-saving your (startup) file",
+              ntree->id.name,
+              owner_id->name);
+    ntree->id.flag |= LIB_EMBEDDED_DATA;
+  }
   ntree->owner_id = owner_id;
 
   /* NOTE: writing and reading goes in sync, for speed. */



More information about the Bf-blender-cvs mailing list