winrt: Fix crash when camera unloaded while searching focus.
Return early from focus related methods when async operation reports that it is write protected. Change-Id: I41bf9121e7ae431e5158b5e4c43cde582c30dfd7 Task-Id: QTBUG-49347 Reviewed-by: Peng Wu <peng.wu@intopalo.com> Reviewed-by: Andrew Knight <andrew.knight@intopalo.com>
This commit is contained in:
@@ -1154,8 +1154,11 @@ bool QWinRTCameraControl::focus()
|
||||
return false;
|
||||
ComPtr<IAsyncAction> op;
|
||||
HRESULT hr = d->focusControl->FocusAsync(&op);
|
||||
if (HRESULT_CODE(hr) == ERROR_OPERATION_IN_PROGRESS)
|
||||
return true;
|
||||
const long errorCode = HRESULT_CODE(hr);
|
||||
if (errorCode == ERROR_OPERATION_IN_PROGRESS
|
||||
|| errorCode == ERROR_WRITE_PROTECT) {
|
||||
return false;
|
||||
}
|
||||
Q_ASSERT_SUCCEEDED(hr);
|
||||
hr = QWinRTFunctions::await(op, QWinRTFunctions::ProcessThreadEvents);
|
||||
Q_ASSERT_SUCCEEDED(hr);
|
||||
@@ -1184,6 +1187,8 @@ bool QWinRTCameraControl::lockFocus()
|
||||
Q_ASSERT_SUCCEEDED(hr);
|
||||
ComPtr<IAsyncAction> op;
|
||||
hr = focusControl2->LockAsync(&op);
|
||||
if (HRESULT_CODE(hr) == ERROR_WRITE_PROTECT)
|
||||
return false;
|
||||
Q_ASSERT_SUCCEEDED(hr);
|
||||
return QWinRTFunctions::await(op) == S_OK;
|
||||
}
|
||||
@@ -1198,6 +1203,8 @@ bool QWinRTCameraControl::unlockFocus()
|
||||
Q_ASSERT_SUCCEEDED(hr);
|
||||
ComPtr<IAsyncAction> op;
|
||||
hr = focusControl2->UnlockAsync(&op);
|
||||
if (HRESULT_CODE(hr) == ERROR_WRITE_PROTECT)
|
||||
return false;
|
||||
Q_ASSERT_SUCCEEDED(hr);
|
||||
return QWinRTFunctions::await(op) == S_OK;
|
||||
}
|
||||
|
||||
@@ -104,10 +104,10 @@ void QWinRTCameraLocksControl::searchAndLockFocus()
|
||||
} else {
|
||||
m_focusLockStatus = QCamera::Searching;
|
||||
emit lockStatusChanged(QCamera::LockFocus, m_focusLockStatus, QCamera::LockAcquired);
|
||||
cameraControl->focus();
|
||||
cameraControl->lockFocus();
|
||||
m_focusLockStatus = QCamera::Locked;
|
||||
emit lockStatusChanged(QCamera::LockFocus, m_focusLockStatus, QCamera::LockAcquired);
|
||||
if (cameraControl->focus()) {
|
||||
m_focusLockStatus = cameraControl->lockFocus() ? QCamera::Locked : QCamera::Unlocked;
|
||||
emit lockStatusChanged(QCamera::LockFocus, m_focusLockStatus, QCamera::LockAcquired);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,8 +117,7 @@ void QWinRTCameraLocksControl::unlockFocus()
|
||||
return;
|
||||
QWinRTCameraControl *cameraControl = qobject_cast<QWinRTCameraControl *>(parent());
|
||||
Q_ASSERT(cameraControl);
|
||||
cameraControl->unlockFocus();
|
||||
m_focusLockStatus = QCamera::Unlocked;
|
||||
m_focusLockStatus = cameraControl->unlockFocus() ? QCamera::Unlocked : QCamera::Locked;
|
||||
emit lockStatusChanged(QCamera::LockFocus, m_focusLockStatus, QCamera::UserRequest);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user