diff --git a/source/blender/blenloader/BLO_blend_validate.hh b/source/blender/blenloader/BLO_blend_validate.hh index 69f8738a11d..337223dd44f 100644 --- a/source/blender/blenloader/BLO_blend_validate.hh +++ b/source/blender/blenloader/BLO_blend_validate.hh @@ -31,3 +31,13 @@ bool BLO_main_validate_shapekeys(Main *bmain, ReportList *reports); * was split in `ID.tag`, which can create crashing situations in some rare cases, see #117795. */ void BLO_main_validate_embedded_liboverrides(Main *bmain, ReportList *reports); + +/** + * Check that the `LIB_EMBEDDED_DATA` flag is correctly set for embedded IDs, and not for any Main + * ID. + * + * NOTE: It is unknown why/how this can happen, but there are some files out there that have e.g. + * Objects flagged as embedded data... See e.g. the `(Anim) Hero p23 for 2.blend` file from our + * cloud gallery (https://cloud.blender.org/p/gallery/5b642e25bf419c1042056fc6). + */ +void BLO_main_validate_embedded_flag(Main *bmain, ReportList *reports); diff --git a/source/blender/blenloader/intern/blend_validate.cc b/source/blender/blenloader/intern/blend_validate.cc index 5ca9d7c466f..175c4fef4df 100644 --- a/source/blender/blenloader/intern/blend_validate.cc +++ b/source/blender/blenloader/intern/blend_validate.cc @@ -13,6 +13,8 @@ #include /* for #strrchr #strncmp #strstr */ +#include "CLG_log.h" + #include "BLI_utildefines.h" #include "BLI_linklist.h" @@ -38,6 +40,8 @@ #include "readfile.hh" +static CLG_LogRef LOG = {"blo.blend_validate"}; + bool BLO_main_validate_libraries(Main *bmain, ReportList *reports) { ListBase mainlist; @@ -234,3 +238,37 @@ void BLO_main_validate_embedded_liboverrides(Main *bmain, ReportList * /*reports } FOREACH_MAIN_ID_END; } + +void BLO_main_validate_embedded_flag(Main *bmain, ReportList * /*reports*/) +{ + ID *id_iter; + FOREACH_MAIN_ID_BEGIN (bmain, id_iter) { + if (id_iter->flag & LIB_EMBEDDED_DATA) { + CLOG_ERROR( + &LOG, "ID %s is flagged as embedded, while existing in Main data-base", id_iter->name); + id_iter->flag &= ~LIB_EMBEDDED_DATA; + } + + bNodeTree *node_tree = ntreeFromID(id_iter); + if (node_tree) { + if ((node_tree->id.flag & LIB_EMBEDDED_DATA) == 0) { + CLOG_ERROR(&LOG, + "ID %s has an embedded nodetree which is not flagged as embedded", + id_iter->name); + node_tree->id.flag |= LIB_EMBEDDED_DATA; + } + } + + if (GS(id_iter->name) == ID_SCE) { + Scene *scene = reinterpret_cast(id_iter); + if (scene->master_collection && (scene->master_collection->id.flag & LIB_EMBEDDED_DATA) == 0) + { + CLOG_ERROR(&LOG, + "ID %s has an embedded Collection which is not flagged as embedded", + id_iter->name); + scene->master_collection->id.flag |= LIB_EMBEDDED_DATA; + } + } + } + FOREACH_MAIN_ID_END; +} diff --git a/source/blender/blenloader/intern/readfile.cc b/source/blender/blenloader/intern/readfile.cc index 239018e278f..fae1862047a 100644 --- a/source/blender/blenloader/intern/readfile.cc +++ b/source/blender/blenloader/intern/readfile.cc @@ -3335,6 +3335,7 @@ static void after_liblink_merged_bmain_process(Main *bmain, BlendFileReadReport * so simpler to just use it directly in this single call. */ BLO_main_validate_shapekeys(bmain, reports ? reports->reports : nullptr); + BLO_main_validate_embedded_flag(bmain, reports ? reports->reports : nullptr); BLO_main_validate_embedded_liboverrides(bmain, reports ? reports->reports : nullptr); /* We have to rebuild that runtime information *after* all data-blocks have been properly linked.