Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorBastien Montagne <bastien@blender.org>2021-03-15 17:19:22 +0300
committerBastien Montagne <bastien@blender.org>2021-03-15 17:21:40 +0300
commit992abd4734a04b493e32ed900d4c7a786fd71549 (patch)
treedc3c81e254f87c55de3e9d7e8fc742ba88396046 /source
parentab6e67767e730309e51fca7a7f086cbcbadb41a9 (diff)
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.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_lib_override.h6
-rw-r--r--source/blender/blenkernel/intern/lib_override.c48
-rw-r--r--source/blender/blenloader/intern/readfile.c1
3 files changed, 55 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_lib_override.h b/source/blender/blenkernel/BKE_lib_override.h
index ccb313f0e2a..e0cb2d9abb0 100644
--- a/source/blender/blenkernel/BKE_lib_override.h
+++ b/source/blender/blenkernel/BKE_lib_override.h
@@ -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);
diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c
index 7a6e7a35724..6cdc7fce34b 100644
--- a/source/blender/blenkernel/intern/lib_override.c
+++ b/source/blender/blenkernel/intern/lib_override.c
@@ -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.
*
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 369c10a65b4..f97f6f65551 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -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);
}