From ae539afafba44022ca1c36fed6f47a85d581f523 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Wed, 22 Jul 2015 07:23:12 -0400 Subject: [PATCH] Fix deadlock when using textoverlay from main thread --- interface/src/Application.cpp | 6 +++++- interface/src/ui/overlays/TextOverlay.cpp | 11 ++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f0dcdd1a8a..e194e99688 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4474,7 +4474,11 @@ void Application::friendsWindowClosed() { } void Application::postLambdaEvent(std::function f) { - QCoreApplication::postEvent(this, new LambdaEvent(f)); + if (this->thread() == QThread::currentThread()) { + f(); + } else { + QCoreApplication::postEvent(this, new LambdaEvent(f)); + } } void Application::initPlugins() { diff --git a/interface/src/ui/overlays/TextOverlay.cpp b/interface/src/ui/overlays/TextOverlay.cpp index 467014427d..ea0c4f6026 100644 --- a/interface/src/ui/overlays/TextOverlay.cpp +++ b/interface/src/ui/overlays/TextOverlay.cpp @@ -85,7 +85,6 @@ TextOverlay::TextOverlay() : _topMargin(DEFAULT_MARGIN), _fontSize(DEFAULT_FONTSIZE) { - qApp->postLambdaEvent([=] { static std::once_flag once; std::call_once(once, [] { @@ -117,7 +116,7 @@ TextOverlay::TextOverlay(const TextOverlay* textOverlay) : }); }); while (!_qmlElement) { - QThread::sleep(1); + QThread::msleep(1); } } @@ -147,14 +146,12 @@ xColor TextOverlay::getBackgroundColor() { } void TextOverlay::render(RenderArgs* args) { + if (!_qmlElement) { + return; + } if (_visible != _qmlElement->isVisible()) { _qmlElement->setVisible(_visible); } - float pulseLevel = updatePulse(); - static float _oldPulseLevel = 0.0f; - if (pulseLevel != _oldPulseLevel) { - - } }