[v1] apps: qcam: Do nothing if no camera is selected
diff mbox series

Message ID 20250822150854.591964-1-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • [v1] apps: qcam: Do nothing if no camera is selected
Related show

Commit Message

Barnabás Pőcze Aug. 22, 2025, 3:08 p.m. UTC
If the currently selected camera disappears as reported by the `cameraRemoved`
signal, then `MainWindow::camera_` is reset to `nullptr`. In this case,
pressing the start/stop button will try to start streaming, leading to
a nullptr derefence in `MainWindow::startCapture()` when the configuration
is generated for the camera.

Fix that by returning from `MainWindow::toggleCapture()` if no camera is set.
While this will cause the "checked" status of `startStopAction_` to go out of
sync, this should not be an issue because when a new camera is selected, the
state is synchronized.

Bug: https://bugs.libcamera.org/show_bug.cgi?id=177
Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 src/apps/qcam/main_window.cpp | 3 +++
 1 file changed, 3 insertions(+)

Comments

Kieran Bingham Aug. 23, 2025, 9:24 p.m. UTC | #1
Quoting Barnabás Pőcze (2025-08-22 16:08:54)
> If the currently selected camera disappears as reported by the `cameraRemoved`
> signal, then `MainWindow::camera_` is reset to `nullptr`. In this case,
> pressing the start/stop button will try to start streaming, leading to
> a nullptr derefence in `MainWindow::startCapture()` when the configuration
> is generated for the camera.
> 
> Fix that by returning from `MainWindow::toggleCapture()` if no camera is set.
> While this will cause the "checked" status of `startStopAction_` to go out of
> sync, this should not be an issue because when a new camera is selected, the
> state is synchronized.
> 
> Bug: https://bugs.libcamera.org/show_bug.cgi?id=177
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> ---
>  src/apps/qcam/main_window.cpp | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/src/apps/qcam/main_window.cpp b/src/apps/qcam/main_window.cpp
> index 7e3f3da60..96a2d5090 100644
> --- a/src/apps/qcam/main_window.cpp
> +++ b/src/apps/qcam/main_window.cpp
> @@ -333,6 +333,9 @@ int MainWindow::openCamera()
>  
>  void MainWindow::toggleCapture(bool start)
>  {
> +       if (!camera_)

I wondered if we should update the user with a status bar message or
such - but we don't have one ... so there's not much we can do...

I expect the Icon stays at the play symbol ... which should be fine.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> +               return;
> +
>         if (start) {
>                 startCapture();
>                 startStopAction_->setIcon(iconStop_);
> -- 
> 2.50.1
>

Patch
diff mbox series

diff --git a/src/apps/qcam/main_window.cpp b/src/apps/qcam/main_window.cpp
index 7e3f3da60..96a2d5090 100644
--- a/src/apps/qcam/main_window.cpp
+++ b/src/apps/qcam/main_window.cpp
@@ -333,6 +333,9 @@  int MainWindow::openCamera()
 
 void MainWindow::toggleCapture(bool start)
 {
+	if (!camera_)
+		return;
+
 	if (start) {
 		startCapture();
 		startStopAction_->setIcon(iconStop_);