Fix T84586: missing Outliner redraws for certain NLA operators

Outliner display under 'Animation' > 'NLA Tracks' was not updating in
the following cases:
- adding strips
- removing strips
- duplicating strips (possibly to different track)
- swapping strips
- reordering tracks
- changing strip order by translating
- translating strips between tracks
- renaming tracks

In the case of deleting strips/tracks, this was also resulting in a use-
after-free error in Outliner drawing code (this was reported specifically
in T84586).

Most of these operators already sent a ND_NLA|NA_EDITED notifier, but the
Outliner is not listening to these. Listening to NA_EDITED is also not
what we want since this also happens a lot in cases irrelevant to the
Outliner. Now be a bit more specific and send ND_NLA|NA_ADDED / ND_NLA|
NA_REMOVED or a new ND_NLA_ORDER (to distinguish from NA_EDITED
'only' - where a redraw is not neccessary) and listen to these from the
Outliner.

(note: places that were listening to ND_NLA|NA_EDITED before are also
listening to NA_ADDED or NA_REMOVED, so changing NA_EDITED should not be
a problem here)

(note 2: for cases like swapping tracks/strips order, NA_ADDED or
NA_REMOVED does not make sense, neither can we use NA_EDITED [since we
dont want to listen to this], so in this case an additional ND_NLA_ORDER
is now sent)

(note 3: in nla transform code, this is now always sent on confirm. There
are cases were the notifier would not be needed, but checking exactly all
cases were it actually would be needed seems overkill [history of D10073
has example code to check if strips moved between tracks])

Maniphest Tasks: T84586

Differential Revision: https://developer.blender.org/D10073
This commit is contained in:
Philipp Oeser 2021-01-11 13:56:15 +01:00
parent dfdf79fb03
commit b4530deec4
Notes: blender-bot 2023-06-12 00:52:52 +02:00
Referenced by issue #84586, Use-after-free when expanding hierarchy in Outliner after deleting NLA track
Referenced by issue #84486, When a strip is cut and edited in nla editor, the strip returns to its original length without the cut. blender 2.92 alpha
7 changed files with 41 additions and 13 deletions

View File

@ -1580,6 +1580,7 @@ static int animchannels_rearrange_exec(bContext *C, wmOperator *op)
/* send notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA_ORDER, NULL);
return OPERATOR_FINISHED;
}
@ -2900,6 +2901,7 @@ static int animchannels_rename_invoke(bContext *C, wmOperator *UNUSED(op), const
/* handle click */
if (rename_anim_channels(&ac, channel_index)) {
WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_RENAME, NULL);
return OPERATOR_FINISHED;
}

View File

@ -1730,7 +1730,7 @@ static int object_speaker_add_exec(bContext *C, wmOperator *op)
BLI_strncpy(nlt->name, DATA_("SoundTrack"), sizeof(nlt->name));
BKE_nlastrip_validate_name(adt, strip);
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_ADDED, NULL);
}
return OPERATOR_FINISHED;

View File

@ -735,7 +735,7 @@ static int nlaedit_add_tracks_exec(bContext *C, wmOperator *op)
DEG_relations_tag_update(CTX_data_main(C));
/* set notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_ADDED, NULL);
/* done */
return OPERATOR_FINISHED;
@ -823,7 +823,7 @@ static int nlaedit_delete_tracks_exec(bContext *C, wmOperator *UNUSED(op))
DEG_relations_tag_update(ac.bmain);
/* set notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_REMOVED, NULL);
/* done */
return OPERATOR_FINISHED;

View File

@ -693,7 +693,7 @@ static int nlaedit_add_actionclip_exec(bContext *C, wmOperator *op)
DEG_relations_tag_update(ac.bmain);
/* set notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_ADDED, NULL);
/* done */
return OPERATOR_FINISHED;
@ -823,7 +823,7 @@ static int nlaedit_add_transition_exec(bContext *C, wmOperator *op)
ED_nla_postop_refresh(&ac);
/* set notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_ADDED, NULL);
/* done */
return OPERATOR_FINISHED;
@ -920,7 +920,7 @@ static int nlaedit_add_sound_exec(bContext *C, wmOperator *UNUSED(op))
ED_nla_postop_refresh(&ac);
/* set notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_ADDED, NULL);
/* done */
return OPERATOR_FINISHED;
@ -992,7 +992,7 @@ static int nlaedit_add_meta_exec(bContext *C, wmOperator *UNUSED(op))
ANIM_animdata_freelist(&anim_data);
/* set notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_ADDED, NULL);
/* done */
return OPERATOR_FINISHED;
@ -1053,7 +1053,7 @@ static int nlaedit_remove_meta_exec(bContext *C, wmOperator *UNUSED(op))
ANIM_animdata_freelist(&anim_data);
/* set notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_REMOVED, NULL);
/* done */
return OPERATOR_FINISHED;
@ -1155,7 +1155,7 @@ static int nlaedit_duplicate_exec(bContext *C, wmOperator *op)
}
/* set notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_ADDED, NULL);
/* done */
return OPERATOR_FINISHED;
@ -1260,7 +1260,7 @@ static int nlaedit_delete_exec(bContext *C, wmOperator *UNUSED(op))
DEG_relations_tag_update(ac.bmain);
/* set notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_REMOVED, NULL);
/* done */
return OPERATOR_FINISHED;
@ -1415,7 +1415,7 @@ static int nlaedit_split_exec(bContext *C, wmOperator *UNUSED(op))
ED_nla_postop_refresh(&ac);
/* set notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_ADDED, NULL);
/* done */
return OPERATOR_FINISHED;
@ -1659,6 +1659,7 @@ static int nlaedit_swap_exec(bContext *C, wmOperator *op)
/* set notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA_ORDER, NULL);
/* done */
return OPERATOR_FINISHED;
@ -1744,6 +1745,7 @@ static int nlaedit_move_up_exec(bContext *C, wmOperator *UNUSED(op))
/* set notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA_ORDER, NULL);
/* done */
return OPERATOR_FINISHED;
@ -1829,6 +1831,7 @@ static int nlaedit_move_down_exec(bContext *C, wmOperator *UNUSED(op))
/* set notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA_ORDER, NULL);
/* done */
return OPERATOR_FINISHED;
@ -2002,7 +2005,7 @@ static int nlaedit_make_single_user_exec(bContext *C, wmOperator *UNUSED(op))
}
/* set notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_ADDED, NULL);
/* done */
return OPERATOR_FINISHED;
@ -2241,6 +2244,8 @@ static int nlaedit_snap_exec(bContext *C, wmOperator *op)
scene = ac.scene;
secf = (float)FPS;
bool any_added = false;
/* since we may add tracks, perform this in reverse order */
for (ale = anim_data.last; ale; ale = ale->prev) {
ListBase tmp_strips = {NULL, NULL};
@ -2314,6 +2319,8 @@ static int nlaedit_snap_exec(bContext *C, wmOperator *op)
/* clear temp meta-strips on this new track,
* as we may not be able to get back to it */
BKE_nlastrips_clear_metas(&track->strips, 0, 1);
any_added = true;
}
}
@ -2333,6 +2340,9 @@ static int nlaedit_snap_exec(bContext *C, wmOperator *op)
/* set notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_EDITED, NULL);
if (any_added) {
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_ADDED, NULL);
}
/* done */
return OPERATOR_FINISHED;

View File

@ -222,10 +222,18 @@ static void outliner_main_region_listener(wmWindow *UNUSED(win),
ED_region_tag_redraw(region);
break;
case ND_ANIMCHAN:
if (wmn->action == NA_SELECTED) {
if (ELEM(wmn->action, NA_SELECTED, NA_RENAME)) {
ED_region_tag_redraw(region);
}
break;
case ND_NLA:
if (ELEM(wmn->action, NA_ADDED, NA_REMOVED)) {
ED_region_tag_redraw(region);
}
break;
case ND_NLA_ORDER:
ED_region_tag_redraw(region);
break;
}
break;
case NC_GPENCIL:

View File

@ -36,6 +36,7 @@
#include "ED_markers.h"
#include "WM_api.h"
#include "WM_types.h"
#include "RNA_access.h"
@ -554,6 +555,12 @@ void special_aftertrans_update__nla(bContext *C, TransInfo *UNUSED(t))
BKE_nlastrips_clear_metas(&nlt->strips, 0, 1);
}
/* General refresh for the outliner because the following might have happened:
* - strips moved between tracks
* - strips swapped order
* - duplicate-move moves to different track. */
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_ADDED, NULL);
/* free temp memory */
ANIM_animdata_freelist(&anim_data);

View File

@ -392,6 +392,7 @@ typedef struct wmNotifier {
#define ND_NLA (73 << 16)
#define ND_NLA_ACTCHANGE (74 << 16)
#define ND_FCURVES_ORDER (75 << 16)
#define ND_NLA_ORDER (76 << 16)
/* NC_GPENCIL */
#define ND_GPENCIL_EDITMODE (85 << 16)