Skip to content

Commit 3f153d5

Browse files
committed
🐛 Fix: Avoid a exception / crash on a bad cast, also comment around memory leaking
1 parent 724191a commit 3f153d5

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Sources/objc/opentimelineio.mm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,9 @@ CxxTimeRange timeline_range_of_child(CxxRetainer* self, CxxRetainer* child, CxxE
720720
NSArray* timeline_find_clips(CxxRetainer* self, CxxErrorStruct* cxxErr) {
721721
auto array = [NSMutableArray new];
722722
_AutoErrorHandler aeh(cxxErr);
723+
// find_clips() returns pointers to Clips owned by the Timeline's composition
724+
// hierarchy. NSValue wraps them for transport to Swift, where findOrCreate()
725+
// creates properly-retained wrappers. Same pattern as composition_children_in_range().
723726
for (auto t: SO_cast<otio::Timeline>(self)->find_clips(&aeh.error_status)) {
724727
[array addObject: [NSValue valueWithPointer: t]];
725728
}

Sources/swift/Timeline.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ public class Timeline : SerializableObjectWithMetadata {
8282
var result = [Clip]()
8383
for child in children_array {
8484
if let nsptr = child as? NSValue, let cxxPtr = nsptr.pointerValue {
85-
result.append(SerializableObject.findOrCreate(cxxPtr: cxxPtr) as! Clip)
85+
if let clip = SerializableObject.findOrCreate(cxxPtr: cxxPtr) as? Clip {
86+
result.append(clip)
87+
}
8688
}
8789
}
8890
return result

0 commit comments

Comments
 (0)