[Bf-blender-cvs] [da6bda64839] master: Fix T60783: (Certain) shapekeys stopped working in 2.8.

Bastien Montagne noreply at git.blender.org
Fri Jan 25 17:48:08 CET 2019


Commit: da6bda64839e91dea4e6a7c144f8ae30e2d9076b
Author: Bastien Montagne
Date:   Fri Jan 25 17:42:43 2019 +0100
Branches: master
https://developer.blender.org/rBda6bda64839e91dea4e6a7c144f8ae30e2d9076b

Fix T60783: (Certain) shapekeys stopped working in 2.8.

This commit adds another optional check (when `--debug-io` is set) on
write .blend process, to check and ensure all shape keys have their
'from' pointer properly set to their respective user ID.
This is intended to be used as debuging tool mostly (to try to detect
when/why some of those pointers can become NULL).

For now, it also systematically perform same checks/fixes when loading a
.blend file, to fix all broken ones laying around. Later we might move
that usage to a do_version instead, but for now think it's safer to
always perfom it (and it's rather cheap process anyway).

===================================================================

M	source/blender/blenloader/BLO_blend_validate.h
M	source/blender/blenloader/intern/blend_validate.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c

===================================================================

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 */



More information about the Bf-blender-cvs mailing list