From eb7337391fb3a8e7e2001393ba0642ef237ec400 Mon Sep 17 00:00:00 2001 From: Martin Vajnar Date: Sun, 6 May 2018 12:49:46 +0200 Subject: [PATCH] SHAPE: Fix undefined behavior resulting in strange lock-ups This commit fixes intermittent freezes of 'subscriber' dialog. These freezes were caused by invoking QWidget::update() directly from a non-GUI thread. This is undefined behavior and leads to many strange lock-ups and even SEGFAULTS. In order to fix this we now introduce the signal changed(), that will be emitted if repaint of shapes is requested either from publisher or subscriber. This signal is connected to the update() slot. By default signals are connected to slots by Qt::AutoConnection connection type. This should ensure, that QT decides internally if it should treat this connection as Qt::DirectConnection in case of publisher and Qt::QueuedConnection in case of subscriber. This decision is made when the signal is emitted. --- orte/contrib/shape/MyQFrame.cpp | 6 ++++-- orte/contrib/shape/MyQFrame.h | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/orte/contrib/shape/MyQFrame.cpp b/orte/contrib/shape/MyQFrame.cpp index 997498c..8743270 100644 --- a/orte/contrib/shape/MyQFrame.cpp +++ b/orte/contrib/shape/MyQFrame.cpp @@ -14,6 +14,8 @@ MyQFrame::MyQFrame( QWidget *parent) { mousePressed=0; objects[0]=objects[1]=objects[2]=objects[3]=objects[4]=0; + + connect(this,SIGNAL(changed()),this,SLOT(update())); } @@ -33,12 +35,12 @@ void MyQFrame::activateObject(int object,int color, int shape) { void MyQFrame::deactivateObject(int object) { if (object>4) return; objects[object]=0; - update(); + emit changed(); } void MyQFrame::setPosition(int object,QRect position) { positions[object]=position; - update(); + emit changed(); } void MyQFrame::paintEvent(QPaintEvent*) diff --git a/orte/contrib/shape/MyQFrame.h b/orte/contrib/shape/MyQFrame.h index c6b3d47..f5f05a2 100644 --- a/orte/contrib/shape/MyQFrame.h +++ b/orte/contrib/shape/MyQFrame.h @@ -41,6 +41,9 @@ public: int mousePressed; int mouseX; int mouseY; + +signals: + void changed(void); }; #endif // MyQFRAME_H -- 2.39.2