Fix T83869: Crash when creating Sequencer in new scene

Crash on null dereference in `SEQ_timeline_boundbox()`. This function was
generalized in rB9e4a4c2e996c to work on arbitrary `seqbase`.

Fixed by refactoring `SEQ_timeline_boundbox()` functions to return default
sane values if `seqbase` is `NULL`

Reviewed By: HooglyBoogly

Differential Revision: https://developer.blender.org/D9878
This commit is contained in:
Richard Antalik 2020-12-17 02:11:22 +01:00
parent 3a1d1aaa86
commit d11b219d40
Notes: blender-bot 2023-02-13 20:10:17 +01:00
Referenced by issue #83869, Crash when "creating" Video Sequencer on a new scene.
5 changed files with 34 additions and 25 deletions

View File

@ -2305,7 +2305,7 @@ void draw_timeline_seq(const bContext *C, ARegion *region)
UI_view2d_view_ortho(v2d);
/* Get timeline bound-box, needed for the scroll-bars. */
SEQ_timeline_boundbox(scene, ed->seqbasep, &v2d->tot);
SEQ_timeline_boundbox(scene, SEQ_active_seqbase_get(ed), &v2d->tot);
draw_seq_backdrop(v2d);
UI_view2d_constant_grid_draw(v2d, FPS);

View File

@ -90,11 +90,7 @@ static int sequencer_view_all_exec(bContext *C, wmOperator *op)
Scene *scene = CTX_data_scene(C);
const Editing *ed = BKE_sequencer_editing_get(scene, false);
if (ed == NULL) {
return OPERATOR_FINISHED;
}
SEQ_timeline_boundbox(scene, ed->seqbasep, &box);
SEQ_timeline_boundbox(scene, SEQ_active_seqbase_get(ed), &box);
UI_view2d_smooth_view(C, region, &box, smooth_viewtx);
return OPERATOR_FINISHED;
}

View File

@ -194,6 +194,7 @@ struct SequencerToolSettings *SEQ_tool_settings_copy(struct SequencerToolSetting
struct Editing *BKE_sequencer_editing_get(struct Scene *scene, bool alloc);
struct Editing *BKE_sequencer_editing_ensure(struct Scene *scene);
void BKE_sequencer_editing_free(struct Scene *scene, const bool do_id_user);
struct ListBase *SEQ_active_seqbase_get(const struct Editing *ed);
void BKE_sequencer_sort(struct Scene *scene);
struct Sequence *BKE_sequencer_from_elem(ListBase *seqbase, struct StripElem *se);
struct Sequence *BKE_sequencer_active_get(struct Scene *scene);

View File

@ -327,6 +327,20 @@ void SEQ_tool_settings_fit_method_set(Scene *scene, eSeqImageFitMethod fit_metho
tool_settings->fit_method = fit_method;
}
/**
* Get seqbase that is being viewed currently. This can be main seqbase or meta strip seqbase
*
* \param ed: sequence editor data
* \return pointer to active seqbase. returns NULL if ed is NULL
*/
ListBase *SEQ_active_seqbase_get(const Editing *ed)
{
if (ed == NULL) {
return NULL;
}
return ed->seqbasep;
}
/** \} */
/* -------------------------------------------------------------------- */

View File

@ -361,28 +361,26 @@ float BKE_sequence_get_fps(Scene *scene, Sequence *seq)
*/
void SEQ_timeline_boundbox(const Scene *scene, const ListBase *seqbase, rctf *rect)
{
float min[2], max[2];
min[0] = scene->r.sfra;
max[0] = scene->r.efra + 1;
min[1] = 0.0;
max[1] = 8.0;
rect->xmin = scene->r.sfra;
rect->xmax = scene->r.efra + 1;
rect->ymin = 0.0f;
rect->ymax = 8.0f;
LISTBASE_FOREACH (Sequence *, seq, seqbase) {
if (min[0] > seq->startdisp - 1) {
min[0] = seq->startdisp - 1;
}
if (max[0] < seq->enddisp + 1) {
max[0] = seq->enddisp + 1;
}
if (max[1] < seq->machine + 2) {
max[1] = seq->machine + 2;
}
if (seqbase == NULL) {
return;
}
rect->xmin = min[0];
rect->xmax = max[0];
rect->ymin = min[1];
rect->ymax = max[1];
LISTBASE_FOREACH (Sequence *, seq, seqbase) {
if (rect->xmin > seq->startdisp - 1) {
rect->xmin = seq->startdisp - 1;
}
if (rect->xmax < seq->enddisp + 1) {
rect->xmax = seq->enddisp + 1;
}
if (rect->ymax < seq->machine + 2) {
rect->ymax = seq->machine + 2;
}
}
}
/**