Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.11.1, 5.11.2
-
None
Description
When destroying the QCamera we have crashes inside the DirectShow plugin for the camera (DSCameraControl)
In previous versions the code was:
DSCameraControl::DSCameraControl(QObject *parent)
: QCameraControl(parent)
, m_state(QCamera::UnloadedState)
, m_captureMode(QCamera::CaptureStillImage)
so the connection was implicitly destroyed when object was also destroyed.
In version Qt5.11.1 & Qt5.11.2 this code has changed using a lamda function into:
DSCameraControl::DSCameraControl(QObject *parent)
: QCameraControl(parent)
, m_state(QCamera::UnloadedState)
, m_captureMode(QCamera::CaptureStillImage)
{
m_session = qobject_cast<DSCameraSession*>(parent);
connect(m_session, &DSCameraSession::statusChanged,
[&](QCamera::Status status)
);
connect(m_session, &DSCameraSession::cameraError,
this, &DSCameraControl::error);
}
So the lamda function is called even if the object is destroyed, hence the crash.
A solution we found working is the modification below:
DSCameraControl::DSCameraControl(QObject *parent)
: QCameraControl(parent)
, m_state(QCamera::UnloadedState)
, m_captureMode(QCamera::CaptureStillImage)
{
m_session = qobject_cast<DSCameraSession*>(parent);
connect(m_session, &DSCameraSession::statusChanged, this,
[&](QCamera::Status status)
);
connect(m_session, &DSCameraSession::cameraError,
this, &DSCameraControl::error);
}