diff --git a/OSBindings/Qt/functionthread.h b/OSBindings/Qt/functionthread.h index 947787ec2..20ae65353 100644 --- a/OSBindings/Qt/functionthread.h +++ b/OSBindings/Qt/functionthread.h @@ -25,6 +25,10 @@ class FunctionThread: public QThread { while(performerFlag.test_and_set()); } + ~FunctionThread() { + stop(); + } + void run() override { // Gymnastics here: events posted directly to the QThread will occur on the thread // that created the QThread. To have events occur within a QThread, they have to be @@ -35,9 +39,11 @@ class FunctionThread: public QThread { } void stop() { - performAsync([this] { - this->quit(); - }); + if(isRunning()) { + performAsync([this] { + this->quit(); + }); + } wait(); } diff --git a/OSBindings/Qt/timer.cpp b/OSBindings/Qt/timer.cpp index 914107170..46ccd59c7 100644 --- a/OSBindings/Qt/timer.cpp +++ b/OSBindings/Qt/timer.cpp @@ -34,7 +34,9 @@ void Timer::tick() { Timer::~Timer() { thread.performAsync([this] { - timer->stop(); + if(timer) { + timer->stop(); + } }); thread.stop(); }