diff --git a/ResourceManager.cpp b/ResourceManager.cpp index be53d270..e7965b1b 100644 --- a/ResourceManager.cpp +++ b/ResourceManager.cpp @@ -106,6 +106,7 @@ void ResourceManager::DetectDevices() void ResourceManager::DetectDevicesThreadFunction() { + DetectDeviceMutex.lock(); unsigned int prev_count = 0; float percent = 0.0f; @@ -175,4 +176,12 @@ void ResourceManager::DetectDevicesThreadFunction() } profile_manager.LoadSizeFromProfile("sizes.ors"); + + DetectDeviceMutex.unlock(); +} + +void ResourceManager::WaitForDeviceDetection() +{ + DetectDeviceMutex.lock(); + DetectDeviceMutex.unlock(); } diff --git a/ResourceManager.h b/ResourceManager.h index ccb0e029..abed6c8d 100644 --- a/ResourceManager.h +++ b/ResourceManager.h @@ -44,6 +44,8 @@ public: void DetectDevicesThreadFunction(); + void WaitForDeviceDetection(); + private: static std::unique_ptr instance; @@ -60,6 +62,8 @@ private: std::thread * DetectDevicesThread; + std::mutex DetectDeviceMutex; + std::mutex DeviceListChangeMutex; std::vector DeviceListChangeCallbacks; std::vector DeviceListChangeCallbackArgs; diff --git a/qt/OpenRGBDialog2.cpp b/qt/OpenRGBDialog2.cpp index a6447bc7..b7996336 100644 --- a/qt/OpenRGBDialog2.cpp +++ b/qt/OpenRGBDialog2.cpp @@ -7,6 +7,7 @@ #include #include #include +#include using namespace Ui; @@ -184,6 +185,12 @@ OpenRGBDialog2::~OpenRGBDialog2() delete ui; } +void OpenRGBDialog2::closeEvent(QCloseEvent *event) +{ + ResourceManager::get()->WaitForDeviceDetection(); + event->accept(); +} + void OpenRGBDialog2::AddI2CToolsPage() { /*-----------------------------------------------------*\ diff --git a/qt/OpenRGBDialog2.h b/qt/OpenRGBDialog2.h index b9742ae3..a6f144a4 100644 --- a/qt/OpenRGBDialog2.h +++ b/qt/OpenRGBDialog2.h @@ -66,6 +66,7 @@ private: void ClearDevicesList(); void UpdateDevicesList(); void UpdateProfileList(); + void closeEvent(QCloseEvent *event); private slots: void on_Exit();