Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2018-11-07 15:55:29 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2018-11-07 22:58:53 +0300
commit4779165ca18ae3ced005aad129575b70fc6c4f9d (patch)
treed1e70f122a31b87ac0137074aa1d561dc3bf1329 /source/blender/blenkernel/intern
parenta0d8e52b54ea9c27b47ddf96ff51cc934534d40e (diff)
Fix dpesgraph wrongly refcounting NLA strip actions when duplicating IDs.
NLA strips are users of their action, so we need to pass along ID management flags. This commit also cleans up a bit things by passing along ID_CREATE/COPY flags instead of dummy booleans...
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r--source/blender/blenkernel/intern/anim_sys.c25
-rw-r--r--source/blender/blenkernel/intern/library.c31
-rw-r--r--source/blender/blenkernel/intern/nla.c33
3 files changed, 50 insertions, 39 deletions
diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c
index b08038f67af..639e4f40004 100644
--- a/source/blender/blenkernel/intern/anim_sys.c
+++ b/source/blender/blenkernel/intern/anim_sys.c
@@ -266,11 +266,18 @@ void BKE_animdata_free(ID *id, const bool do_id_user)
/* Copying -------------------------------------------- */
-/* Make a copy of the given AnimData - to be used when copying datablocks */
-AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const bool do_action, const bool do_id_user)
+/**
+ * Make a copy of the given AnimData - to be used when copying datablocks.
+ * \param flag Control ID pointers management, see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_library.h
+ * \return The copied animdata.
+ */
+AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const int flag)
{
AnimData *dadt;
+ const bool do_action = (flag & LIB_ID_COPY_ACTIONS) != 0 && (flag & LIB_ID_CREATE_NO_MAIN) == 0;
+ const bool do_id_user = (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0;
+
/* sanity check before duplicating struct */
if (adt == NULL)
return NULL;
@@ -288,7 +295,7 @@ AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const bool do_action, co
}
/* duplicate NLA data */
- BKE_nla_tracks_copy(bmain, &dadt->nla_tracks, &adt->nla_tracks);
+ BKE_nla_tracks_copy(bmain, &dadt->nla_tracks, &adt->nla_tracks, flag);
/* duplicate drivers (F-Curves) */
copy_fcurves(&dadt->drivers, &adt->drivers);
@@ -301,19 +308,23 @@ AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const bool do_action, co
return dadt;
}
-bool BKE_animdata_copy_id(Main *bmain, ID *id_to, ID *id_from, const bool do_action, const bool do_id_user)
+/**
+ * \param flag Control ID pointers management, see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_library.h
+ * \return true is succesfully copied.
+ */
+bool BKE_animdata_copy_id(Main *bmain, ID *id_to, ID *id_from, const int flag)
{
AnimData *adt;
if ((id_to && id_from) && (GS(id_to->name) != GS(id_from->name)))
return false;
- BKE_animdata_free(id_to, do_id_user);
+ BKE_animdata_free(id_to, (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0);
adt = BKE_animdata_from_id(id_from);
if (adt) {
IdAdtTemplate *iat = (IdAdtTemplate *)id_to;
- iat->adt = BKE_animdata_copy(bmain, adt, do_action, do_id_user);
+ iat->adt = BKE_animdata_copy(bmain, adt, flag);
}
return true;
@@ -373,7 +384,7 @@ void BKE_animdata_merge_copy(
if (src->nla_tracks.first) {
ListBase tracks = {NULL, NULL};
- BKE_nla_tracks_copy(bmain, &tracks, &src->nla_tracks);
+ BKE_nla_tracks_copy(bmain, &tracks, &src->nla_tracks, 0);
BLI_movelisttolist(&dst->nla_tracks, &tracks);
}
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index ff663cfab01..74c3341fa96 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -1416,18 +1416,6 @@ void *BKE_id_new_nomain(const short type, const char *name)
return id;
}
-/* by spec, animdata is first item after ID */
-/* and, trust that BKE_animdata_from_id() will only find AnimData for valid ID-types */
-static void id_copy_animdata(Main *bmain, ID *id, const bool do_action, const bool do_id_user)
-{
- AnimData *adt = BKE_animdata_from_id(id);
-
- if (adt) {
- IdAdtTemplate *iat = (IdAdtTemplate *)id;
- iat->adt = BKE_animdata_copy(bmain, iat->adt, do_action, do_id_user);
- }
-}
-
void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag)
{
ID *new_id = *r_newid;
@@ -1478,16 +1466,17 @@ void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int fla
}
#endif
- /* the duplicate should get a copy of the animdata */
- if ((flag & LIB_ID_COPY_NO_ANIMDATA) == 0) {
- BLI_assert((flag & LIB_ID_COPY_ACTIONS) == 0 || (flag & LIB_ID_CREATE_NO_MAIN) == 0);
- id_copy_animdata(bmain, new_id,
- (flag & LIB_ID_COPY_ACTIONS) != 0 && (flag & LIB_ID_CREATE_NO_MAIN) == 0,
- (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0);
- }
- else if (id_can_have_animdata(new_id)) {
+ if (id_can_have_animdata(new_id)) {
IdAdtTemplate *iat = (IdAdtTemplate *)new_id;
- iat->adt = NULL;
+
+ /* the duplicate should get a copy of the animdata */
+ if ((flag & LIB_ID_COPY_NO_ANIMDATA) == 0) {
+ BLI_assert((flag & LIB_ID_COPY_ACTIONS) == 0 || (flag & LIB_ID_CREATE_NO_MAIN) == 0);
+ iat->adt = BKE_animdata_copy(bmain, iat->adt, flag);
+ }
+ else {
+ iat->adt = NULL;
+ }
}
if ((flag & LIB_ID_CREATE_NO_DEG_TAG) == 0 && (flag & LIB_ID_CREATE_NO_MAIN) == 0) {
diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c
index 8c5cc6f2b38..192e6b5e56e 100644
--- a/source/blender/blenkernel/intern/nla.c
+++ b/source/blender/blenkernel/intern/nla.c
@@ -163,12 +163,15 @@ void BKE_nla_tracks_free(ListBase *tracks, bool do_id_user)
* Copy NLA strip
*
* \param use_same_action When true, the existing action is used (instead of being duplicated)
+ * \param flag Control ID pointers management, see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_library.h
*/
-NlaStrip *BKE_nlastrip_copy(Main *bmain, NlaStrip *strip, const bool use_same_action)
+NlaStrip *BKE_nlastrip_copy(Main *bmain, NlaStrip *strip, const bool use_same_action, const int flag)
{
NlaStrip *strip_d;
NlaStrip *cs, *cs_d;
+ const bool do_id_user = (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0;
+
/* sanity check */
if (strip == NULL)
return NULL;
@@ -180,12 +183,14 @@ NlaStrip *BKE_nlastrip_copy(Main *bmain, NlaStrip *strip, const bool use_same_ac
/* handle action */
if (strip_d->act) {
if (use_same_action) {
- /* increase user-count of action */
- id_us_plus(&strip_d->act->id);
+ if (do_id_user) {
+ /* increase user-count of action */
+ id_us_plus(&strip_d->act->id);
+ }
}
else {
/* use a copy of the action instead (user count shouldn't have changed yet) */
- strip_d->act = BKE_action_copy(bmain, strip_d->act);
+ BKE_id_copy_ex(bmain, &strip_d->act->id, (ID **)&strip_d->act, flag, false);
}
}
@@ -197,7 +202,7 @@ NlaStrip *BKE_nlastrip_copy(Main *bmain, NlaStrip *strip, const bool use_same_ac
BLI_listbase_clear(&strip_d->strips);
for (cs = strip->strips.first; cs; cs = cs->next) {
- cs_d = BKE_nlastrip_copy(bmain, cs, use_same_action);
+ cs_d = BKE_nlastrip_copy(bmain, cs, use_same_action, flag);
BLI_addtail(&strip_d->strips, cs_d);
}
@@ -205,8 +210,11 @@ NlaStrip *BKE_nlastrip_copy(Main *bmain, NlaStrip *strip, const bool use_same_ac
return strip_d;
}
-/* Copy NLA Track */
-NlaTrack *BKE_nlatrack_copy(Main *bmain, NlaTrack *nlt, const bool use_same_actions)
+/**
+ * Copy a single NLA Track.
+ * \param flag Control ID pointers management, see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_library.h
+ */
+NlaTrack *BKE_nlatrack_copy(Main *bmain, NlaTrack *nlt, const bool use_same_actions, const int flag)
{
NlaStrip *strip, *strip_d;
NlaTrack *nlt_d;
@@ -223,7 +231,7 @@ NlaTrack *BKE_nlatrack_copy(Main *bmain, NlaTrack *nlt, const bool use_same_acti
BLI_listbase_clear(&nlt_d->strips);
for (strip = nlt->strips.first; strip; strip = strip->next) {
- strip_d = BKE_nlastrip_copy(bmain, strip, use_same_actions);
+ strip_d = BKE_nlastrip_copy(bmain, strip, use_same_actions, flag);
BLI_addtail(&nlt_d->strips, strip_d);
}
@@ -231,8 +239,11 @@ NlaTrack *BKE_nlatrack_copy(Main *bmain, NlaTrack *nlt, const bool use_same_acti
return nlt_d;
}
-/* Copy all NLA data */
-void BKE_nla_tracks_copy(Main *bmain, ListBase *dst, ListBase *src)
+/**
+ * Copy all NLA data.
+ * \param flag Control ID pointers management, see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_library.h
+ */
+void BKE_nla_tracks_copy(Main *bmain, ListBase *dst, ListBase *src, const int flag)
{
NlaTrack *nlt, *nlt_d;
@@ -247,7 +258,7 @@ void BKE_nla_tracks_copy(Main *bmain, ListBase *dst, ListBase *src)
for (nlt = src->first; nlt; nlt = nlt->next) {
/* make a copy, and add the copy to the destination list */
// XXX: we need to fix this sometime
- nlt_d = BKE_nlatrack_copy(bmain, nlt, true);
+ nlt_d = BKE_nlatrack_copy(bmain, nlt, true, flag);
BLI_addtail(dst, nlt_d);
}
}