diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2019-01-25 19:42:43 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2019-01-25 19:46:09 +0300 |
commit | da6bda64839e91dea4e6a7c144f8ae30e2d9076b (patch) | |
tree | 6b046a55002674067219a30a70581eed3f48e685 /source/blender/blenloader/intern/blend_validate.c | |
parent | a42441d1451e9b89120dff0039aa09f122369ebe (diff) |
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).
Diffstat (limited to 'source/blender/blenloader/intern/blend_validate.c')
-rw-r--r-- | source/blender/blenloader/intern/blend_validate.c | 39 |
1 files changed, 37 insertions, 2 deletions
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; +} |