Skip to content

Commit 438c545

Browse files
committed
Reduce time it takes to close preview dialog
1 parent da42183 commit 438c545

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/macro-external/opencv/preview-dialog.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "utility.hpp"
55

66
#include <screenshot-helper.hpp>
7-
#include <condition_variable>
87

98
PreviewDialog::PreviewDialog(QWidget *parent, int delay)
109
: QDialog(parent),
@@ -119,6 +118,7 @@ void PreviewDialog::SelectArea()
119118
void PreviewDialog::Stop()
120119
{
121120
_stop = true;
121+
_cv.notify_all();
122122
if (_thread.joinable()) {
123123
_thread.join();
124124
}
@@ -189,13 +189,12 @@ void PreviewDialog::Start()
189189

190190
void PreviewDialog::CheckForMatchLoop()
191191
{
192-
std::condition_variable cv;
193192
while (!_stop) {
194193
std::unique_lock<std::mutex> lock(_mtx);
195194
auto source = obs_weak_source_get_source(_video.GetVideo());
196195
ScreenshotHelper screenshot(source);
197196
obs_source_release(source);
198-
cv.wait_for(lock, std::chrono::milliseconds(_delay));
197+
_cv.wait_for(lock, std::chrono::milliseconds(_delay));
199198
if (_stop || isHidden()) {
200199
return;
201200
}

src/macro-external/opencv/preview-dialog.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <thread>
1414
#include <mutex>
15+
#include <condition_variable>
1516

1617
class PreviewDialog : public QDialog {
1718
Q_OBJECT
@@ -62,6 +63,7 @@ private slots:
6263
std::atomic_bool _selectingArea = {false};
6364

6465
std::mutex _mtx;
66+
std::condition_variable _cv;
6567
std::thread _thread;
6668
std::atomic_bool _stop = {true};
6769

0 commit comments

Comments
 (0)