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).
This commit is contained in:
Bastien Montagne 2019-01-25 17:42:43 +01:00
parent a42441d145
commit da6bda6483
Notes: blender-bot 2023-02-14 03:59:43 +01:00
Referenced by issue #60783, (Certain) shapekeys stopped working in 2.8
4 changed files with 44 additions and 2 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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)

View File

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