diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 500ee14f..4fbc088f 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -754,6 +754,11 @@ IDevice::timer_uid_t CPhoneDevice::RegisterHeartbeat(unsigned int timerType, uns bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector& osds, const std::string& path) { + if (m_threadClose.joinable()) + { + m_threadClose.join(); + } + if (mCamera != NULL) { delete mCamera; @@ -1071,7 +1076,7 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat) bool turnOffOtg = (mPhotoInfo.usbCamera != 0); std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, turnOffOtg); - closeThread.detach(); + m_threadClose.swap(closeThread); return res; } @@ -1091,7 +1096,7 @@ bool CPhoneDevice::OnVideoReady(bool result, const char* path, unsigned int phot bool turnOffOtg = (mPhotoInfo.usbCamera != 0); std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, turnOffOtg); - closeThread.detach(); + m_threadClose.swap(closeThread); return result; } diff --git a/app/src/main/cpp/PhoneDevice.h b/app/src/main/cpp/PhoneDevice.h index f941cde9..3ea7fe87 100644 --- a/app/src/main/cpp/PhoneDevice.h +++ b/app/src/main/cpp/PhoneDevice.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -289,6 +290,7 @@ protected: long mCameraPowerCount; long mOtgCount; + std::thread m_threadClose; };