[Bf-blender-cvs] [606f6e73b04] blender-v3.0-release: Fix T94280: Crash when splitting meta strip

Richard Antalik noreply at git.blender.org
Tue Jan 11 09:33:00 CET 2022


Commit: 606f6e73b04c855c6525df1e7e30f112f74268a4
Author: Richard Antalik
Date:   Tue Dec 21 05:27:46 2021 +0100
Branches: blender-v3.0-release
https://developer.blender.org/rB606f6e73b04c855c6525df1e7e30f112f74268a4

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`.

===================================================================

M	source/blender/sequencer/intern/strip_edit.c
M	source/blender/sequencer/intern/strip_time.c
M	source/blender/sequencer/intern/utils.c

===================================================================

diff --git a/source/blender/sequencer/intern/strip_edit.c b/source/blender/sequencer/intern/strip_edit.c
index 747f0eb3deb..7b54d5edb9b 100644
--- a/source/blender/sequencer/intern/strip_edit.c
+++ b/source/blender/sequencer/intern/strip_edit.c
@@ -494,21 +494,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(
@@ -517,20 +523,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);
+  SEQ_edit_remove_flagged_sequences(scene, seqbase);
 
-  for (; seq; seq = seq->next) {
-    SEQ_ensure_unique_name(seq, scene);
+  /* Rename duplicated strips. */
+  Sequence *seq_rename = return_seq;
+  for (; seq_rename; seq_rename = seq_rename->next) {
+    SEQ_ensure_unique_name(seq_rename, 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);
   return return_seq;
 }
 
diff --git a/source/blender/sequencer/intern/strip_time.c b/source/blender/sequencer/intern/strip_time.c
index a8e07f37a0b..220a96c6943 100644
--- a/source/blender/sequencer/intern/strip_time.c
+++ b/source/blender/sequencer/intern/strip_time.c
@@ -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. */
diff --git a/source/blender/sequencer/intern/utils.c b/source/blender/sequencer/intern/utils.c
index 71686065882..ed78f6851ef 100644
--- a/source/blender/sequencer/intern/utils.c
+++ b/source/blender/sequencer/intern/utils.c
@@ -454,7 +454,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;



More information about the Bf-blender-cvs mailing list