Fix (unreported) some old files having regular IDs flagged as embedded.

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).

Not much to be done, but add another checking pass at the end of
readfile process to fix these.
This commit is contained in:
Bastien Montagne 2024-03-23 12:55:57 +09:00
parent 7643bd7d89
commit c7afb06ed0
3 changed files with 49 additions and 0 deletions

View File

@ -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);

View File

@ -13,6 +13,8 @@
#include <cstring> /* 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<Scene *>(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;
}

View File

@ -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.