Skip to content

fix(chat): stop the attach camera preview from reconfiguring on main - #1042

Merged
bmc08gt merged 2 commits into
mainfrom
fix/attach-camera-preview-hang
Oct 11, 2026
Merged

bmc08gt merged 2 commits into
mainfrom
fix/attach-camera-preview-hang

Conversation

@bmc08gt

@bmc08gt bmc08gt commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Fixes Bugsnag 6ac9b0b2991833fd09be1dd8, an App Hang in ChatCameraPreview.makeUIView.

Setting a new AVCaptureVideoPreviewLayer's session on the main thread makes AVCaptureSession commit a configuration. The attach surface mounts the hidden camera card every time it appears, so opening and closing the panel repeated that rebuild on main.

  • ChatPhotoCamera creates one preview layer in init, while the session is still empty. The input added later on the session queue connects to it there.
  • ChatCameraPreview hosts that layer instead of making its own. It sets the frame in layoutSubviews and removes the layer on dismantle only if it is still the view's sublayer, so a remount that already took it keeps it.
  • flip() had the same main-thread beginConfiguration/commitConfiguration. The swap now runs on the session queue; taps during a swap are ignored, and a lens that fails to attach restores the previous input.

Regression_6ac9b0b2991833fd09be1dd8 mounts the preview twice and expects the camera's layer both times. It fails on main.

Bugsnag 6ac9b0b2991833fd09be1dd8 is an App Hang in
ChatCameraPreview.makeUIView. Setting a new preview layer's session on
the main thread makes AVCaptureSession commit a configuration, and the
attach surface mounts the hidden camera card each time it appears, so
toggling the panel repeated that rebuild on main.

ChatPhotoCamera now creates one AVCaptureVideoPreviewLayer in init,
while its session is still empty. The input added later on the session
queue connects to it there. ChatCameraPreview hosts that layer instead
of making its own, sets its frame in layoutSubviews, and removes it on
dismantle only if it is still the view's sublayer, so a remount that
already moved it keeps it.

The regression test mounts the preview twice and expects the camera's
layer both times.
flip() ran its beginConfiguration/commitConfiguration on main, the same
kind of session rebuild behind the attach panel hang. The swap now runs
on the session queue and hands the new input back to main. Taps while a
swap is in flight are ignored, and a lens that fails to attach restores
the previous input.
@bmc08gt bmc08gt self-assigned this Oct 11, 2026
@bmc08gt
bmc08gt merged commit 939eb11 into main Oct 11, 2026
3 checks passed
@bmc08gt
bmc08gt deleted the fix/attach-camera-preview-hang branch October 11, 2026 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant