]> rtime.felk.cvut.cz Git - orte.git/commitdiff
SHAPE: Fix undefined behavior resulting in strange lock-ups
authorMartin Vajnar <Martin.Vajnar@cvut.cz>
Sun, 6 May 2018 10:49:46 +0000 (12:49 +0200)
committerMartin Vajnar <Martin.Vajnar@cvut.cz>
Sun, 6 May 2018 10:49:46 +0000 (12:49 +0200)
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
orte/contrib/shape/MyQFrame.h

index 997498cc0d3b224b05f3b0d238ba3305bd4bb9be..8743270c62c88e3c0abe771dc451a4bfb08a733f 100644 (file)
@@ -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*)
index c6b3d47a20bd874cff8cb6d37085c55e70e9d684..f5f05a293141c90e01d70f970cc81542e22bd8f7 100644 (file)
@@ -41,6 +41,9 @@ public:
     int mousePressed;
     int mouseX;
     int mouseY;
+
+signals:
+    void changed(void);
 };
 
 #endif // MyQFRAME_H