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
diff options
context:
space:
mode:
-rw-r--r--source/blender/blenloader/BLO_blend_validate.h1
-rw-r--r--source/blender/blenloader/intern/blend_validate.c39
-rw-r--r--source/blender/blenloader/intern/readfile.c5
-rw-r--r--source/blender/blenloader/intern/writefile.c1
4 files changed, 44 insertions, 2 deletions
diff --git a/source/blender/blenloader/BLO_blend_validate.h b/source/blender/blenloader/BLO_blend_validate.h
index f9731e19475..42317c1128c 100644
--- a/source/blender/blenloader/BLO_blend_validate.h
+++ b/source/blender/blenloader/BLO_blend_validate.h
@@ -37,5 +37,6 @@ struct Main;
struct ReportList;
bool BLO_main_validate_libraries(struct Main *bmain, struct ReportList *reports);
+bool BLO_main_validate_shapekeys(struct Main *bmain, struct ReportList *reports);
#endif
diff --git a/source/blender/blenloader/intern/blend_validate.c b/source/blender/blenloader/intern/blend_validate.c
index a5d53657152..3f81b400e99 100644
--- a/source/blender/blenloader/intern/blend_validate.c
+++ b/source/blender/blenloader/intern/blend_validate.c
@@ -40,8 +40,10 @@
#include "MEM_guardedalloc.h"
#include "DNA_sdna_types.h"
+#include "DNA_key_types.h"
#include "DNA_windowmanager_types.h"
+#include "BKE_key.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_report.h"
@@ -51,8 +53,8 @@
#include "readfile.h"
-/* Does not fix anything, but checks that all linked data-blocks are still valid (i.e. pointing to the right library). */
-bool BLO_main_validate_libraries(struct Main *bmain, struct ReportList *reports)
+/** Check (but do *not* fix) that all linked data-blocks are still valid (i.e. pointing to the right library). */
+bool BLO_main_validate_libraries(Main *bmain, ReportList *reports)
{
ListBase mainlist;
bool is_valid = true;
@@ -151,3 +153,36 @@ bool BLO_main_validate_libraries(struct Main *bmain, struct ReportList *reports)
return is_valid;
}
+
+/** Check (and fix if needed) that shape key's 'from' pointer is valid. */
+bool BLO_main_validate_shapekeys(Main *bmain, ReportList *reports)
+{
+ bool is_valid = true;
+
+ BKE_main_lock(bmain);
+
+ ListBase *lbarray[MAX_LIBARRAY];
+ int i = set_listbasepointers(bmain, lbarray);
+ while (i--) {
+ for (ID *id = lbarray[i]->first; id != NULL; id = id->next) {
+ if (!BKE_key_idtype_support(GS(id->name))) {
+ break;
+ }
+ if (id->lib == NULL) {
+ /* We assume lib data is valid... */
+ Key *shapekey = BKE_key_from_id(id);
+ if (shapekey != NULL && shapekey->from != id) {
+ is_valid = false;
+ BKE_reportf(reports, RPT_ERROR,
+ "ID %s uses shapekey %s, but its 'from' pointer is invalid (%p), fixing...",
+ id->name, shapekey->id.name, shapekey->from);
+ shapekey->from = id;
+ }
+ }
+ }
+ }
+
+ BKE_main_unlock(bmain);
+
+ return is_valid;
+}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 92e5f34c06f..f27cd7c74e4 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -172,6 +172,7 @@
#include "NOD_socket.h"
#include "BLO_blend_defs.h"
+#include "BLO_blend_validate.h"
#include "BLO_readfile.h"
#include "BLO_undofile.h"
@@ -8873,6 +8874,10 @@ static void lib_link_all(FileData *fd, Main *main)
lib_link_workspaces(fd, main);
lib_link_library(fd, main); /* only init users */
+
+ /* We could integrate that to mesh/curve/lattice lib_link, but this is really cheap process,
+ * so simpler to just use it directly in this single call. */
+ BLO_main_validate_shapekeys(main, NULL);
}
static void direct_link_keymapitem(FileData *fd, wmKeyMapItem *kmi)
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 2e621ab9330..0df90571daa 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -4131,6 +4131,7 @@ bool BLO_write_file(
if (G.debug & G_DEBUG_IO && mainvar->lock != NULL) {
BKE_report(reports, RPT_INFO, "Checking sanity of current .blend file *BEFORE* save to disk");
BLO_main_validate_libraries(mainvar, reports);
+ BLO_main_validate_shapekeys(mainvar, reports);
}
/* open temporary file, so we preserve the original in case we crash */