From f49d438ced7c5874dbf43976d9901a462176f541 Mon Sep 17 00:00:00 2001 From: Sebastian Parborg Date: Fri, 20 Aug 2021 16:30:34 +0200 Subject: Cleanup and remove SEQ_ALL_BEGIN macro We now use a for_each function with callback to iterate through all sequences in the scene. This has the benefit that we now only loop over the sequences in the scene once. Before we would loop over them twice and allocate memory to store temporary data. The allocation of temporary data lead to unintentional memory leaks if the code used returns to exit out of the iteration loop. The new for_each callback method doesn't allocate any temporary data and only iterates though all sequences once. Reviewed By: Richard Antalik, Bastien Montagne Differential Revision: http://developer.blender.org/D12278 --- .../editors/space_sequencer/sequencer_edit.c | 26 ++++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'source/blender/editors/space_sequencer/sequencer_edit.c') diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index 694e5fbb41d..935bc97d0b2 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -2980,6 +2980,22 @@ static int sequencer_export_subtitles_invoke(bContext *C, return OPERATOR_RUNNING_MODAL; } +typedef struct Seq_get_text_cb_data { + ListBase *text_seq; + Scene *scene; +} Seq_get_text_cb_data; + +static bool seq_get_text_strip_cb(Sequence *seq, void *user_data) +{ + Seq_get_text_cb_data *cd = (Seq_get_text_cb_data *)user_data; + /* Only text strips that are not muted and don't end with negative frame. */ + if ((seq->type == SEQ_TYPE_TEXT) && ((seq->flag & SEQ_MUTE) == 0) && + (seq->enddisp > cd->scene->r.sfra)) { + BLI_addtail(cd->text_seq, MEM_dupallocN(seq)); + } + return true; +} + static int sequencer_export_subtitles_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); @@ -3011,14 +3027,10 @@ static int sequencer_export_subtitles_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - /* Only text strips that are not muted and don't end with negative frame. */ - SEQ_ALL_BEGIN (ed, seq) { - if ((seq->type == SEQ_TYPE_TEXT) && ((seq->flag & SEQ_MUTE) == 0) && - (seq->enddisp > scene->r.sfra)) { - BLI_addtail(&text_seq, MEM_dupallocN(seq)); - } + if (ed != NULL) { + Seq_get_text_cb_data cb_data = {&text_seq, scene}; + SEQ_for_each_callback(&ed->seqbase, seq_get_text_strip_cb, &cb_data); } - SEQ_ALL_END; if (BLI_listbase_is_empty(&text_seq)) { BKE_report(op->reports, RPT_ERROR, "No subtitles (text strips) to export"); -- cgit v1.2.3