@@ -128,6 +128,12 @@ overwrite(
128
128
// Find the items to overwrite.
129
129
auto items =
130
130
composition->find_children <Item>(error_status, range, true );
131
+ if (items.empty ())
132
+ {
133
+ if (error_status)
134
+ *error_status = ErrorStatus::NOT_AN_ITEM;
135
+ return ;
136
+ }
131
137
TimeRange item_range =
132
138
composition->trimmed_range_of_child (items.front ()).value ();
133
139
if (1 == items.size () && item_range.contains (range, 0.0 ))
@@ -169,7 +175,7 @@ overwrite(
169
175
first_item->set_source_range (source_range);
170
176
++insert_index;
171
177
}
172
- const TimeRange item_range = item->trimmed_range ();
178
+ item_range = item->trimmed_range ();
173
179
if (range.duration () < item_range.duration () && !is_fill_fit)
174
180
item->set_source_range (
175
181
TimeRange (trimmed_range.start_time (), range.duration ()));
@@ -372,8 +378,20 @@ void trim(
372
378
ErrorStatus* error_status)
373
379
{
374
380
Composition* composition = item->parent ();
381
+ if (!composition)
382
+ {
383
+ if (error_status)
384
+ *error_status = ErrorStatus::NOT_A_CHILD_OF;
385
+ return ;
386
+ }
375
387
auto children = composition->children ();
376
388
const int index = composition->index_of_child (item);
389
+ if (index < 0 )
390
+ {
391
+ if (error_status)
392
+ *error_status = ErrorStatus::NOT_AN_ITEM;
393
+ return ;
394
+ }
377
395
378
396
const TimeRange range = item->trimmed_range ();
379
397
RationalTime start_time = range.start_time ();
@@ -392,7 +410,7 @@ void trim(
392
410
}
393
411
if (delta_out.value () != 0.0 )
394
412
{
395
- const size_t next_index = index + 1 ;
413
+ const int next_index = index + 1 ;
396
414
if (next_index < children.size ())
397
415
{
398
416
auto next = dynamic_retainer_cast<Item>(children[next_index]);
@@ -492,8 +510,8 @@ slice(
492
510
{
493
511
for (auto transition : transitions)
494
512
{
495
- const int index = composition->index_of_child (transition);
496
- composition->remove_child (index );
513
+ const int child_index = composition->index_of_child (transition);
514
+ composition->remove_child (child_index );
497
515
}
498
516
}
499
517
else
@@ -560,6 +578,11 @@ void slide(
560
578
RationalTime const & delta)
561
579
{
562
580
Composition* composition = item->parent ();
581
+ if (!composition)
582
+ {
583
+ return ;
584
+ }
585
+
563
586
const int index = composition->index_of_child (item);
564
587
565
588
// Exit early if we are at the first clip or if the delta is 0.
@@ -604,6 +627,8 @@ void ripple(
604
627
RationalTime const & delta_out,
605
628
ErrorStatus* error_status)
606
629
{
630
+ if (error_status) *error_status = ErrorStatus::OK;
631
+
607
632
const TimeRange range = item->trimmed_range ();
608
633
RationalTime start_time = range.start_time ();
609
634
RationalTime end_time_exclusive = range.end_time_exclusive ();
@@ -651,8 +676,20 @@ roll(
651
676
ErrorStatus* error_status)
652
677
{
653
678
Composition* composition = item->parent ();
679
+ if (!composition)
680
+ {
681
+ if (error_status)
682
+ *error_status = ErrorStatus::NOT_A_CHILD_OF;
683
+ return ;
684
+ }
654
685
auto children = composition->children ();
655
686
const int index = composition->index_of_child (item);
687
+ if (index < 0 )
688
+ {
689
+ if (error_status)
690
+ *error_status = ErrorStatus::NOT_AN_ITEM;
691
+ return ;
692
+ }
656
693
657
694
const TimeRange range = item->trimmed_range ();
658
695
const TimeRange available_range = item->available_range ();
@@ -696,15 +733,15 @@ roll(
696
733
{
697
734
auto next = dynamic_retainer_cast<Item>(children[next_index]);
698
735
TimeRange next_range = next->trimmed_range ();
699
- const TimeRange available_range = next->available_range ();
736
+ const TimeRange next_available_range = next->available_range ();
700
737
RationalTime next_start_time = next_range.start_time ();
701
738
RationalTime out_offset = delta_out;
702
739
703
740
// If avalable range, clamp to it.
704
741
if (!(isEqual (available_range.duration ().value (), 0.0 )))
705
742
{
706
743
RationalTime available_start_time =
707
- available_range .start_time ();
744
+ next_available_range .start_time ();
708
745
if (-out_offset > available_start_time)
709
746
out_offset = -available_start_time;
710
747
}
0 commit comments