From df571078cfafcd0b98f3b84b84e44c97ac8ff7cf Mon Sep 17 00:00:00 2001 From: Rayyan Ansari Date: Sun, 5 Nov 2023 15:40:48 +0000 Subject: CameraManager: wait for camera to be loaded In QCamera in Qt 5, the camera is required to have been loaded before querying its settings and resolutions. Doing so without loading being finished would result in the returned list being empty. See https://doc.qt.io/qt-5.15/qcamera.html#supportedViewfinderSettings Add a QEventLoop that waits for the state to change from Loading to Loaded before supportedViewfinderSettings() is called to ensure that valid information is returned. (Fixes my camera being blank in preview, same issue also presumed to occur when camera is needed in game, fix tested on a USB camera on a Linux system and Qt 5.) --- src/frontend/qt_sdl/CameraManager.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/frontend/qt_sdl/CameraManager.cpp b/src/frontend/qt_sdl/CameraManager.cpp index c158f5a..7f4db5d 100644 --- a/src/frontend/qt_sdl/CameraManager.cpp +++ b/src/frontend/qt_sdl/CameraManager.cpp @@ -16,6 +16,8 @@ with melonDS. If not, see http://www.gnu.org/licenses/. */ +#include + #include "CameraManager.h" #include "Config.h" @@ -256,6 +258,12 @@ void CameraManager::init() if (camDevice) { camDevice->load(); + if (camDevice->status() == QCamera::LoadingStatus) + { + QEventLoop loop; + connect(camDevice, &QCamera::statusChanged, &loop, &QEventLoop::quit); + loop.exec(); + } const QList supported = camDevice->supportedViewfinderSettings(); bool good = false; -- cgit v1.2.3