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:
Samuel Nevala
2015-11-11 10:05:04 +02:00
parent b05fac61e0
commit da0b7aea9a
2 changed files with 14 additions and 8 deletions

View File

@@ -1154,8 +1154,11 @@ bool QWinRTCameraControl::focus()
return false; return false;
ComPtr<IAsyncAction> op; ComPtr<IAsyncAction> op;
HRESULT hr = d->focusControl->FocusAsync(&op); HRESULT hr = d->focusControl->FocusAsync(&op);
if (HRESULT_CODE(hr) == ERROR_OPERATION_IN_PROGRESS) const long errorCode = HRESULT_CODE(hr);
return true; if (errorCode == ERROR_OPERATION_IN_PROGRESS
|| errorCode == ERROR_WRITE_PROTECT) {
return false;
}
Q_ASSERT_SUCCEEDED(hr); Q_ASSERT_SUCCEEDED(hr);
hr = QWinRTFunctions::await(op, QWinRTFunctions::ProcessThreadEvents); hr = QWinRTFunctions::await(op, QWinRTFunctions::ProcessThreadEvents);
Q_ASSERT_SUCCEEDED(hr); Q_ASSERT_SUCCEEDED(hr);
@@ -1184,6 +1187,8 @@ bool QWinRTCameraControl::lockFocus()
Q_ASSERT_SUCCEEDED(hr); Q_ASSERT_SUCCEEDED(hr);
ComPtr<IAsyncAction> op; ComPtr<IAsyncAction> op;
hr = focusControl2->LockAsync(&op); hr = focusControl2->LockAsync(&op);
if (HRESULT_CODE(hr) == ERROR_WRITE_PROTECT)
return false;
Q_ASSERT_SUCCEEDED(hr); Q_ASSERT_SUCCEEDED(hr);
return QWinRTFunctions::await(op) == S_OK; return QWinRTFunctions::await(op) == S_OK;
} }
@@ -1198,6 +1203,8 @@ bool QWinRTCameraControl::unlockFocus()
Q_ASSERT_SUCCEEDED(hr); Q_ASSERT_SUCCEEDED(hr);
ComPtr<IAsyncAction> op; ComPtr<IAsyncAction> op;
hr = focusControl2->UnlockAsync(&op); hr = focusControl2->UnlockAsync(&op);
if (HRESULT_CODE(hr) == ERROR_WRITE_PROTECT)
return false;
Q_ASSERT_SUCCEEDED(hr); Q_ASSERT_SUCCEEDED(hr);
return QWinRTFunctions::await(op) == S_OK; return QWinRTFunctions::await(op) == S_OK;
} }

View File

@@ -104,12 +104,12 @@ void QWinRTCameraLocksControl::searchAndLockFocus()
} else { } else {
m_focusLockStatus = QCamera::Searching; m_focusLockStatus = QCamera::Searching;
emit lockStatusChanged(QCamera::LockFocus, m_focusLockStatus, QCamera::LockAcquired); emit lockStatusChanged(QCamera::LockFocus, m_focusLockStatus, QCamera::LockAcquired);
cameraControl->focus(); if (cameraControl->focus()) {
cameraControl->lockFocus(); m_focusLockStatus = cameraControl->lockFocus() ? QCamera::Locked : QCamera::Unlocked;
m_focusLockStatus = QCamera::Locked;
emit lockStatusChanged(QCamera::LockFocus, m_focusLockStatus, QCamera::LockAcquired); emit lockStatusChanged(QCamera::LockFocus, m_focusLockStatus, QCamera::LockAcquired);
} }
} }
}
void QWinRTCameraLocksControl::unlockFocus() void QWinRTCameraLocksControl::unlockFocus()
{ {
@@ -117,8 +117,7 @@ void QWinRTCameraLocksControl::unlockFocus()
return; return;
QWinRTCameraControl *cameraControl = qobject_cast<QWinRTCameraControl *>(parent()); QWinRTCameraControl *cameraControl = qobject_cast<QWinRTCameraControl *>(parent());
Q_ASSERT(cameraControl); Q_ASSERT(cameraControl);
cameraControl->unlockFocus(); m_focusLockStatus = cameraControl->unlockFocus() ? QCamera::Unlocked : QCamera::Locked;
m_focusLockStatus = QCamera::Unlocked;
emit lockStatusChanged(QCamera::LockFocus, m_focusLockStatus, QCamera::UserRequest); emit lockStatusChanged(QCamera::LockFocus, m_focusLockStatus, QCamera::UserRequest);
} }