Skip to content

Commit

Permalink
Remove leaked renderers appeared on camera switch (#507)
Browse files Browse the repository at this point in the history
Hello @hiroshihorie!

I found that inside **VideoView** on the camera switch the previous
**primaryRenderer** gets leaked because it's not removed from the view's
hierarchy when the transition ends.

See:

![image](https://github.com/user-attachments/assets/b57769be-57c6-4a66-b7b6-d55aeb6bbedd)

Co-authored-by: Hiroshi Horie <[email protected]>
  • Loading branch information
VatamanuBogdan and hiroshihorie authored Oct 27, 2024
1 parent 89a0fa2 commit 04bf827
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Sources/LiveKit/Views/VideoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -705,17 +705,24 @@ extension VideoView: VideoRenderer {
}
self._secondaryRenderer = nil
}

let previousPrimaryRendered = self._primaryRenderer
let completion: (Bool) -> Void = { _ in
previousPrimaryRendered?.removeFromSuperview()
}

// Currently only for iOS
#if os(iOS)
let (mode, duration, position) = _state.read { ($0.transitionMode, $0.transitionDuration, $0.captureDevice?.facingPosition) }
if let transitionOption = mode.toAnimationOption(fromPosition: position) {
UIView.transition(with: self, duration: duration, options: transitionOption, animations: block, completion: nil)
UIView.transition(with: self, duration: duration, options: transitionOption, animations: block, completion: completion)
} else {
block()
completion(true)
}
#else
block()
completion(true)
#endif
}
}
Expand Down

0 comments on commit 04bf827

Please sign in to comment.