Fix T94280: Crash when splitting meta strip

This happens because in `SEQ_time_update_sequence` function
`SEQ_get_meta_by_seqbase` returns uninitialized value. This isn't nice,
but it shouldn't happen in first place. Problem is, that
`SEQ_edit_strip_split` does move strips into detached `ListBase`, so
other functions can't see them anymore. Detached `ListBase` is used
solely to preserve relationships during duplication.

Move strips to original `ListBase` immediately after duplication and
return `NULL` if `SEQ_get_meta_by_seqbase` can't find meta strip.

Splitting itself can still rely on fact, that number of original and
duplicated strips is same and they are placed next to each other in
exactly same order at the end of original `ListBase`.
This commit is contained in:
Richard Antalik 2021-12-21 05:27:46 +01:00
parent 5457b66301
commit e4de5b4657
Notes: blender-bot 2023-02-14 02:13:08 +01:00
Referenced by issue #95983, Video sequence editor crashes blender, when using cut tool on a nested meta strip.
Referenced by issue #94280, Crash when cutting meta-meta
Referenced by issue #93479, 3.0 Potential candidates for corrective releases
3 changed files with 25 additions and 21 deletions

View File

@ -489,21 +489,27 @@ Sequence *SEQ_edit_strip_split(Main *bmain,
ListBase right_strips = {NULL, NULL};
SEQ_sequence_base_dupli_recursive(scene, scene, &right_strips, &left_strips, SEQ_DUPE_ALL, 0);
/* Split strips. */
Sequence *left_seq = left_strips.first;
Sequence *right_seq = right_strips.first;
Sequence *return_seq = right_strips.first;
Sequence *return_seq = NULL;
/* Strips can't be tagged while in detached `seqbase`. Collect all strips which needs to be
* deleted and delay tagging until they are moved back to `seqbase` in `Editing`. */
SeqCollection *strips_to_delete = SEQ_collection_create(__func__);
/* Move strips from detached `ListBase`, otherwise they can't be flagged for removal,
* SEQ_time_update_sequence can fail to update meta strips and they can't be renamed.
* This is because these functions check all strips in `Editing` to manage relationships. */
BLI_movelisttolist(seqbase, &left_strips);
BLI_movelisttolist(seqbase, &right_strips);
/* Split strips. */
while (left_seq && right_seq) {
if (left_seq->startdisp >= timeline_frame) {
SEQ_collection_append_strip(left_seq, strips_to_delete);
SEQ_edit_flag_for_removal(scene, seqbase, left_seq);
}
if (right_seq->enddisp <= timeline_frame) {
SEQ_collection_append_strip(right_seq, strips_to_delete);
SEQ_edit_flag_for_removal(scene, seqbase, right_seq);
}
else if (return_seq == NULL) {
/* Store return value - pointer to strip that will not be removed. */
return_seq = right_seq;
}
seq_edit_split_handle_strip_offsets(
@ -512,20 +518,14 @@ Sequence *SEQ_edit_strip_split(Main *bmain,
right_seq = right_seq->next;
}
seq = right_strips.first;
BLI_movelisttolist(seqbase, &left_strips);
BLI_movelisttolist(seqbase, &right_strips);
for (; seq; seq = seq->next) {
SEQ_ensure_unique_name(seq, scene);
}
Sequence *seq_delete;
SEQ_ITERATOR_FOREACH (seq_delete, strips_to_delete) {
SEQ_edit_flag_for_removal(scene, seqbase, seq_delete);
}
SEQ_edit_remove_flagged_sequences(scene, seqbase);
SEQ_collection_free(strips_to_delete);
/* Rename duplicated strips. */
Sequence *seq_rename = return_seq;
for (; seq_rename; seq_rename = seq_rename->next) {
SEQ_ensure_unique_name(seq_rename, scene);
}
return return_seq;
}

View File

@ -193,6 +193,10 @@ static void seq_time_update_meta_strip(Scene *scene, Sequence *seq_meta)
void SEQ_time_update_meta_strip_range(Scene *scene, Sequence *seq_meta)
{
if (seq_meta == NULL) {
return;
}
seq_time_update_meta_strip(scene, seq_meta);
/* Prevent meta-strip to move in timeline. */

View File

@ -446,7 +446,7 @@ Sequence *SEQ_get_meta_by_seqbase(ListBase *seqbase_main, ListBase *meta_seqbase
{
SeqCollection *strips = SEQ_query_all_strips_recursive(seqbase_main);
Sequence *seq;
Sequence *seq = NULL;
SEQ_ITERATOR_FOREACH (seq, strips) {
if (seq->type == SEQ_TYPE_META && &seq->seqbase == meta_seqbase) {
break;