LibOverride: Add checks to address some degenerate blend file cases

Attempt to work around some full-corruption cases created at the studio.
Not clear how those were created, so not really fixing anything here,
just detecting and 'solving' as best as possible some high corruption of
local overrides.

This is good to have in general anyway, might help prevent further
corruption to happen too.
This commit is contained in:
Bastien Montagne 2021-03-15 15:19:22 +01:00
parent ab6e67767e
commit 992abd4734
3 changed files with 55 additions and 0 deletions

View File

@ -50,6 +50,7 @@ struct Main;
struct Object;
struct PointerRNA;
struct PropertyRNA;
struct ReportList;
struct Scene;
struct ViewLayer;
@ -129,6 +130,11 @@ bool BKE_lib_override_library_property_operation_operands_validate(
struct PropertyRNA *prop_src,
struct PropertyRNA *prop_storage);
void BKE_lib_override_library_validate(struct Main *bmain,
struct ID *id,
struct ReportList *reports);
void BKE_lib_override_library_main_validate(struct Main *bmain, struct ReportList *reports);
bool BKE_lib_override_library_status_check_local(struct Main *bmain, struct ID *local);
bool BKE_lib_override_library_status_check_reference(struct Main *bmain, struct ID *local);

View File

@ -48,6 +48,7 @@
#include "BKE_lib_query.h"
#include "BKE_lib_remap.h"
#include "BKE_main.h"
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BLI_ghash.h"
@ -1540,6 +1541,53 @@ bool BKE_lib_override_library_property_operation_operands_validate(
return true;
}
/** Check against potential \a bmain. */
void BKE_lib_override_library_validate(Main *UNUSED(bmain), ID *id, ReportList *reports)
{
if (id->override_library == NULL) {
return;
}
if (id->override_library->reference == NULL) {
/* This is a template ID, could be linked or local, not an override. */
return;
}
if (id->override_library->reference == id) {
/* Very serious data corruption, cannot do much about it besides removing the reference
* (therefore making the id a local override template one only). */
BKE_reportf(reports,
RPT_ERROR,
"Data corruption: data-block '%s' is using itself as library override reference",
id->name);
id->override_library->reference = NULL;
return;
}
if (id->override_library->reference->lib == NULL) {
/* Very serious data corruption, cannot do much about it besides removing the reference
* (therefore making the id a local override template one only). */
BKE_reportf(reports,
RPT_ERROR,
"Data corruption: data-block '%s' is using another local data-block ('%s') as "
"library override reference",
id->name,
id->override_library->reference->name);
id->override_library->reference = NULL;
return;
}
}
/** Check against potential \a bmain. */
void BKE_lib_override_library_main_validate(Main *bmain, ReportList *reports)
{
ID *id;
FOREACH_MAIN_ID_BEGIN (bmain, id) {
if (id->override_library != NULL) {
BKE_lib_override_library_validate(bmain, id, reports);
}
}
FOREACH_MAIN_ID_END;
}
/**
* Check that status of local data-block is still valid against current reference one.
*

View File

@ -4237,6 +4237,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
* we can re-generate overrides from their references. */
if (fd->memfile == NULL) {
/* Do not apply in undo case! */
BKE_lib_override_library_main_validate(bfd->main, fd->reports);
BKE_lib_override_library_main_update(bfd->main);
}