From cbefef91a4a1d057e2b21a228a746153e49ed2c6 Mon Sep 17 00:00:00 2001 From: BlueMatthew Date: Wed, 17 Jan 2024 20:47:46 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AD=89=E5=BE=85=E5=85=B3=E9=97=AD=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E7=BB=93=E6=9D=9F=E5=86=8D=E7=BB=A7=E7=BB=AD=E4=B8=8B?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E6=8B=8D=E7=85=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/PhoneDevice.cpp | 9 +++++++-- app/src/main/cpp/PhoneDevice.h | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) 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; };