Unverified Commit 98643b5f authored by Gus Grubba's avatar Gus Grubba Committed by GitHub

Merge pull request #7227 from mavlink/crashOnCameraDisconnect

Fix crash bug that could occur when reconnecting a camera.
parents 660a791d 1683185c
......@@ -12,8 +12,9 @@
QGC_LOGGING_CATEGORY(CameraManagerLog, "CameraManagerLog")
//-----------------------------------------------------------------------------
QGCCameraManager::CameraStruct::CameraStruct(QObject* parent)
QGCCameraManager::CameraStruct::CameraStruct(QObject* parent, uint8_t compID_)
: QObject(parent)
, compID(compID_)
{
}
......@@ -112,7 +113,7 @@ QGCCameraManager::_handleHeartbeat(const mavlink_message_t &message)
QString sCompID = QString::number(message.compid);
if(!_cameraInfoRequest.contains(sCompID)) {
qCDebug(CameraManagerLog) << "Hearbeat from " << message.compid;
CameraStruct* pInfo = new CameraStruct(this);
CameraStruct* pInfo = new CameraStruct(this, message.compid);
pInfo->lastHeartbeat.start();
_cameraInfoRequest[sCompID] = pInfo;
//-- Request camera info
......@@ -226,19 +227,22 @@ QGCCameraManager::_cameraTimeout()
//-- Has the camera stopped talking to us?
if(pInfo->lastHeartbeat.elapsed() > 5000) {
//-- Camera is gone. Remove it.
bool autoStream = false;
QGCCameraControl* pCamera = _findCamera(pInfo->compID);
qWarning() << "Camera" << pCamera->modelName() << "stopped transmitting. Removing from list.";
int idx = _cameraLabels.indexOf(pCamera->modelName());
if(idx >= 0) {
_cameraLabels.removeAt(idx);
}
idx = _cameras.indexOf(pCamera);
if(idx >= 0) {
_cameras.removeAt(idx);
if(pCamera) {
qWarning() << "Camera" << pCamera->modelName() << "stopped transmitting. Removing from list.";
int idx = _cameraLabels.indexOf(pCamera->modelName());
if(idx >= 0) {
_cameraLabels.removeAt(idx);
}
idx = _cameras.indexOf(pCamera);
if(idx >= 0) {
_cameras.removeAt(idx);
}
autoStream = pCamera->autoStream();
pCamera->deleteLater();
delete pInfo;
}
bool autoStream = pCamera->autoStream();
pCamera->deleteLater();
delete pInfo;
_cameraInfoRequest.remove(sCompID);
emit cameraLabelsChanged();
//-- If we have another camera, switch current camera.
......
......@@ -76,7 +76,7 @@ protected:
class CameraStruct : public QObject {
public:
CameraStruct(QObject* parent);
CameraStruct(QObject* parent, uint8_t compID_);
QTime lastHeartbeat;
bool infoReceived = false;
bool gaveUp = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment