diff options
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; +} |