Skip to content

fix(desktop qr): show an error on Linux when the camera can't be opened - #1488

Open
sneurlax wants to merge 1 commit into
fix/qr-image-file-decodingfrom
fix/linux-qr-camera-timeout
Open

sneurlax wants to merge 1 commit into
fix/qr-image-file-decodingfrom
fix/linux-qr-camera-timeout

Conversation

@sneurlax

@sneurlax sneurlax commented Nov 1, 2026

Copy link
Copy Markdown
Member

Base: fix/qr-image-file-decoding. Third of three stacked PRs on top of the Windows QR camera fix.

On Linux, opening the QR dialog with no working camera shows a spinner forever instead of an error.

Cause

camera_linux's initializeCamera() only starts a capture thread and never fails. If OpenCV can't open a camera, the thread exits, and captureImage() keeps returning empty frames (or throws on a null frame pointer) indefinitely. The dialog treated a successful initializeCamera() as an open camera and kept polling. Also, the plugin was constructed in a field initializer, and its constructor dlopens libcamera_linux.so, so a missing or broken library threw outside the dialog's error handling.

Change

All in lib/widgets/desktop/qr_code_scanner_dialog.dart:

  • Linux: the plugin is constructed inside _initializeCamera's try, so a library load failure becomes the dialog's normal "unable to open the camera" error.
  • After initializeCamera(), the dialog waits up to 10 seconds for a first non-empty frame. If none arrives, it stops the plugin and shows that error, with the usual pointer to "Select file".
  • While scanning, on every desktop platform, the "camera is not returning images" error now appears after 10 seconds without a usable frame. It used to appear after 20 consecutive exceptions. Empty and undecodable frames count towards the 10 seconds, and any good frame resets it.
  • TimeoutException gets a readable message in the init error.

This only changes when the error appears. Capture and decoding are unchanged.

camera_linux's initializeCamera() only starts a capture thread, so with no
camera it succeeds and captureImage() returns empty frames forever, leaving
the dialog spinning. Wait up to 10 s for a first frame and report the camera
as unavailable otherwise. Create the plugin inside the guarded init, since
its constructor throws if libcamera_linux.so can't be loaded. On every
platform, show an error once no usable frame has arrived for 10 s instead
of only after 20 capture exceptions.
@sneurlax
sneurlax added this pull request to stack #1487 November 1, 2026 21:03
@sneurlax sneurlax added the bug Something isn't working label Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant