Skip to content

Commit a02381c

Browse files
meshulaDavid Baraffnporcino-pixar
authored
make Timeline::set_tracks(null_ptr) create a new Stack to fix crash (#961)
* make Timeline::set_tracks(null_ptr) create a new Stack, just like the constructor does Co-authored-by: David Baraff <nosuch@nowhere> Co-authored-by: Nick Porcino <[email protected]>
1 parent 2f4a3c5 commit a02381c

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/opentimelineio/timeline.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Timeline::Timeline(std::string const& name,
1313
Timeline::~Timeline() {
1414
}
1515

16+
void Timeline::set_tracks(Stack* stack) {
17+
_tracks = stack ? stack : new Stack("tracks");
18+
}
19+
1620
bool Timeline::read_from(Reader& reader) {
1721
return reader.read("tracks", &_tracks) &&
1822
reader.read_if_present("global_start_time", &_global_start_time) &&

src/opentimelineio/timeline.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ class Timeline : public SerializableObjectWithMetadata {
3030
}*/
3131

3232

33-
void set_tracks(Stack* stack) {
34-
_tracks = stack;
35-
}
33+
void set_tracks(Stack* stack);
3634

3735
optional<RationalTime> const& global_start_time() const {
3836
return _global_start_time;

tests/test_timeline.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,24 @@ def test_tracks(self):
494494
[t.name for t in tl.audio_tracks()]
495495
)
496496

497+
def test_tracks_set_null_tracks(self):
498+
tl = otio.schema.Timeline(tracks=[
499+
otio.schema.Track(
500+
name="V1",
501+
kind=otio.schema.TrackKind.Video
502+
),
503+
otio.schema.Track(
504+
name="V2",
505+
kind=otio.schema.TrackKind.Video
506+
)])
507+
508+
self.assertEqual(len(tl.tracks), 2)
509+
self.assertTrue(isinstance(tl.tracks, otio.schema.Stack))
510+
tl.tracks = None
511+
self.assertEqual(len(tl.audio_tracks()), 0)
512+
self.assertEqual(len(tl.video_tracks()), 0)
513+
self.assertTrue(isinstance(tl.tracks, otio.schema.Stack))
514+
497515

498516
if __name__ == '__main__':
499517
unittest.main()

0 commit comments

Comments
 (0)