From 2554a6788925b52a70ec9f90e33a57a373b1d04f Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Sun, 6 May 2012 01:03:51 +0000 Subject: Deleting action constraints (and a few others) now adjusts the usercounts of their referenced data correctly --- source/blender/blenkernel/intern/constraint.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'source/blender/blenkernel/intern/constraint.c') diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 66209e8a924..0ce3807fecb 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -4318,17 +4318,31 @@ bConstraintTypeInfo *constraint_get_typeinfo (bConstraint *con) /* ---------- Data Management ------- */ +/* helper function for free_constraint_data() - unlinks references */ +static void con_unlink_refs_cb(bConstraint *UNUSED(con), ID **idpoin, short isReference, void *UNUSED(userData)) +{ + if (*idpoin && isReference) + id_us_min(*idpoin); +} + /* Free data of a specific constraint if it has any info. * be sure to run BIK_clear_data() when freeing an IK constraint, - * unless DAG_scene_sort is called. */ + * unless DAG_scene_sort is called. + */ void free_constraint_data(bConstraint *con) { if (con->data) { bConstraintTypeInfo *cti= constraint_get_typeinfo(con); - /* perform any special freeing constraint may have */ - if (cti && cti->free_data) - cti->free_data(con); + if (cti) { + /* perform any special freeing constraint may have */ + if (cti->free_data) + cti->free_data(con); + + /* unlink the referenced resources it uses */ + if (cti->id_looper) + cti->id_looper(con, con_unlink_refs_cb, NULL); + } /* free constraint data now */ MEM_freeN(con->data); -- cgit v1.2.3