Commit: ca3f601f9372f08b1772d6dfa04dbc85c96ea8c9
Author: Bastien Montagne
Date:   Thu Aug 10 12:56:32 2017 +0200
Branches: master
https://developer.blender.org/rBca3f601f9372f08b1772d6dfa04dbc85c96ea8c9

Fix T52332: crash when duplicating sequencer strips.

Bug introduced in recent ID copying refactor.

This commit basically sanitizes seq strip copying behavior, by making
destination scene pointer mandatory (and source one a const one).
Nothing then prevents you from using same pointer as source and
destination!

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

M       source/blender/blenkernel/BKE_sequencer.h
M       source/blender/blenkernel/intern/sequencer.c
M       source/blender/editors/space_sequencer/sequencer_edit.c

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

diff --git a/source/blender/blenkernel/BKE_sequencer.h 
b/source/blender/blenkernel/BKE_sequencer.h
index 87d63b7d6f6..f3e3abab87a 100644
--- a/source/blender/blenkernel/BKE_sequencer.h
+++ b/source/blender/blenkernel/BKE_sequencer.h
@@ -335,7 +335,8 @@ bool BKE_sequence_base_shuffle(
 bool BKE_sequence_base_shuffle_time(ListBase *seqbasep, struct Scene 
*evil_scene);
 bool BKE_sequence_base_isolated_sel_check(struct ListBase *seqbase);
 void BKE_sequencer_free_imbuf(struct Scene *scene, struct ListBase *seqbasep, 
bool for_render);
-struct Sequence *BKE_sequence_dupli_recursive(struct Scene *scene, struct 
Scene *scene_to, struct Sequence *seq, int dupe_flag);
+struct Sequence *BKE_sequence_dupli_recursive(
+        const struct Scene *scene, struct Scene *scene_to, struct Sequence 
*seq, int dupe_flag);
 int BKE_sequence_swap(struct Sequence *seq_a, struct Sequence *seq_b, const 
char **error_str);
 
 bool BKE_sequence_check_depend(struct Sequence *seq, struct Sequence *cur);
diff --git a/source/blender/blenkernel/intern/sequencer.c 
b/source/blender/blenkernel/intern/sequencer.c
index a7991139b3f..76335f484cf 100644
--- a/source/blender/blenkernel/intern/sequencer.c
+++ b/source/blender/blenkernel/intern/sequencer.c
@@ -5371,9 +5371,8 @@ Sequence *BKE_sequencer_add_movie_strip(bContext *C, 
ListBase *seqbasep, SeqLoad
        return seq;
 }
 
-static Sequence *seq_dupli(Scene *scene, Scene *scene_to, Sequence *seq, int 
dupe_flag, const int flag)
+static Sequence *seq_dupli(const Scene *scene, Scene *scene_to, Sequence *seq, 
int dupe_flag, const int flag)
 {
-       Scene *sce_audio = scene_to ? scene_to : scene;
        Sequence *seqn = MEM_dupallocN(seq);
 
        seq->tmp = seqn;
@@ -5416,7 +5415,7 @@ static Sequence *seq_dupli(Scene *scene, Scene *scene_to, 
Sequence *seq, int dup
        else if (seq->type == SEQ_TYPE_SCENE) {
                seqn->strip->stripdata = NULL;
                if (seq->scene_sound)
-                       seqn->scene_sound = 
BKE_sound_scene_add_scene_sound_defaults(sce_audio, seqn);
+                       seqn->scene_sound = 
BKE_sound_scene_add_scene_sound_defaults(scene_to, seqn);
        }
        else if (seq->type == SEQ_TYPE_MOVIECLIP) {
                /* avoid assert */
@@ -5433,7 +5432,7 @@ static Sequence *seq_dupli(Scene *scene, Scene *scene_to, 
Sequence *seq, int dup
                seqn->strip->stripdata =
                        MEM_dupallocN(seq->strip->stripdata);
                if (seq->scene_sound)
-                       seqn->scene_sound = 
BKE_sound_add_scene_sound_defaults(sce_audio, seqn);
+                       seqn->scene_sound = 
BKE_sound_add_scene_sound_defaults(scene_to, seqn);
 
                if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
                        id_us_plus((ID *)seqn->sound);
@@ -5457,11 +5456,15 @@ static Sequence *seq_dupli(Scene *scene, Scene 
*scene_to, Sequence *seq, int dup
                BLI_assert(0);
        }
 
-       if (dupe_flag & SEQ_DUPE_UNIQUE_NAME)
-               BKE_sequence_base_unique_name_recursive(&scene->ed->seqbase, 
seqn);
+       if (scene == scene_to) {
+               if (dupe_flag & SEQ_DUPE_UNIQUE_NAME) {
+                       
BKE_sequence_base_unique_name_recursive(&scene_to->ed->seqbase, seqn);
+               }
 
-       if (dupe_flag & SEQ_DUPE_ANIM)
-               BKE_sequencer_dupe_animdata(scene, seq->name + 2, seqn->name + 
2);
+               if (dupe_flag & SEQ_DUPE_ANIM) {
+                       BKE_sequencer_dupe_animdata(scene_to, seq->name + 2, 
seqn->name + 2);
+               }
+       }
 
        return seqn;
 }
@@ -5488,7 +5491,7 @@ static void seq_new_fix_links_recursive(Sequence *seq)
        }
 }
 
-Sequence *BKE_sequence_dupli_recursive(Scene *scene, Scene *scene_to, Sequence 
*seq, int dupe_flag)
+Sequence *BKE_sequence_dupli_recursive(const Scene *scene, Scene *scene_to, 
Sequence *seq, int dupe_flag)
 {
        Sequence *seqn;
 
@@ -5522,7 +5525,7 @@ void BKE_sequence_base_dupli_recursive(
        for (seq = seqbase->first; seq; seq = seq->next) {
                seq->tmp = NULL;
                if ((seq->flag & SELECT) || (dupe_flag & SEQ_DUPE_ALL)) {
-                       seqn = seq_dupli((Scene *)scene, scene_to, seq, 
dupe_flag, flag);
+                       seqn = seq_dupli(scene, scene_to, seq, dupe_flag, flag);
                        if (seqn) { /*should never fail */
                                if (dupe_flag & SEQ_DUPE_CONTEXT) {
                                        seq->flag &= ~SEQ_ALLSEL;
diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c 
b/source/blender/editors/space_sequencer/sequencer_edit.c
index 1ace61481a6..b22a158e151 100644
--- a/source/blender/editors/space_sequencer/sequencer_edit.c
+++ b/source/blender/editors/space_sequencer/sequencer_edit.c
@@ -727,7 +727,7 @@ static Sequence *cut_seq_hard(Scene *scene, Sequence *seq, 
int cutframe)
 
        if (!skip_dup) {
                /* Duplicate AFTER the first change */
-               seqn = BKE_sequence_dupli_recursive(scene, NULL, seq, 
SEQ_DUPE_UNIQUE_NAME | SEQ_DUPE_ANIM);
+               seqn = BKE_sequence_dupli_recursive(scene, scene, seq, 
SEQ_DUPE_UNIQUE_NAME | SEQ_DUPE_ANIM);
        }
        
        if (seqn) {
@@ -820,7 +820,7 @@ static Sequence *cut_seq_soft(Scene *scene, Sequence *seq, 
int cutframe)
 
        if (!skip_dup) {
                /* Duplicate AFTER the first change */
-               seqn = BKE_sequence_dupli_recursive(scene, NULL, seq, 
SEQ_DUPE_UNIQUE_NAME | SEQ_DUPE_ANIM);
+               seqn = BKE_sequence_dupli_recursive(scene, scene, seq, 
SEQ_DUPE_UNIQUE_NAME | SEQ_DUPE_ANIM);
        }
        
        if (seqn) {
@@ -2162,7 +2162,7 @@ static int sequencer_add_duplicate_exec(bContext *C, 
wmOperator *UNUSED(op))
        if (ed == NULL)
                return OPERATOR_CANCELLED;
 
-       BKE_sequence_base_dupli_recursive(scene, NULL, &nseqbase, ed->seqbasep, 
SEQ_DUPE_CONTEXT, 0);
+       BKE_sequence_base_dupli_recursive(scene, scene, &nseqbase, 
ed->seqbasep, SEQ_DUPE_CONTEXT, 0);
 
        if (nseqbase.first) {
                Sequence *seq = nseqbase.first;
@@ -3200,7 +3200,7 @@ static int sequencer_copy_exec(bContext *C, wmOperator 
*op)
                return OPERATOR_CANCELLED;
        }
 
-       BKE_sequence_base_dupli_recursive(scene, NULL, &nseqbase, ed->seqbasep, 
SEQ_DUPE_UNIQUE_NAME, 0);
+       BKE_sequence_base_dupli_recursive(scene, scene, &nseqbase, 
ed->seqbasep, SEQ_DUPE_UNIQUE_NAME, 0);
 
        /* To make sure the copied strips have unique names between each other 
add
         * them temporarily to the end of the original seqbase. (bug 25932)
@@ -3267,7 +3267,7 @@ static int sequencer_paste_exec(bContext *C, wmOperator 
*UNUSED(op))
        ED_sequencer_deselect_all(scene);
        ofs = scene->r.cfra - seqbase_clipboard_frame;
 
-       BKE_sequence_base_dupli_recursive(scene, NULL, &nseqbase, 
&seqbase_clipboard, SEQ_DUPE_UNIQUE_NAME, 0);
+       BKE_sequence_base_dupli_recursive(scene, scene, &nseqbase, 
&seqbase_clipboard, SEQ_DUPE_UNIQUE_NAME, 0);
 
        /* transform pasted strips before adding */
        if (ofs) {

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to