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.
This commit is contained in:
parent
e047b2618a
commit
e46687c3aa
|
@ -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);
|
||||
|
|
|
@ -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. */
|
||||
|
|
Loading…
Reference in New Issue