Commit 4cf13c8dd27124a567eee9aca3da06b42e63555d

Authored by Charles Otto
1 parent 96bc6989

Fix a periodic crash when running br -objects without -useGui 0

Fix a crash periodically manifested in br -objects which was caused by
ShowTrainingTransform's transform * creating and deleting a ShowTransform so
quickly that its associated window still had incoming messages when it was
deleted in ShowTransform's destructor.

By using the deleteLater slot instead of calling delete directly we can be sure
that incoming events are processed before the window is deleted.
Showing 1 changed file with 10 additions and 2 deletions
openbr/plugins/gui.cpp
@@ -176,6 +176,10 @@ public: @@ -176,6 +176,10 @@ public:
176 setFixedSize(200,200); 176 setFixedSize(200,200);
177 QApplication::instance()->installEventFilter(this); 177 QApplication::instance()->installEventFilter(this);
178 } 178 }
  179 + ~DisplayWindow()
  180 + {
  181 + QApplication::instance()->removeEventFilter(this);
  182 + }
179 183
180 public slots: 184 public slots:
181 void showImage(const QPixmap & input) 185 void showImage(const QPixmap & input)
@@ -193,7 +197,6 @@ public slots: @@ -193,7 +197,6 @@ public slots:
193 setFixedSize(temp); 197 setFixedSize(temp);
194 } 198 }
195 199
196 -  
197 bool eventFilter(QObject * obj, QEvent * event) 200 bool eventFilter(QObject * obj, QEvent * event)
198 { 201 {
199 if (event->type() == QEvent::KeyPress) 202 if (event->type() == QEvent::KeyPress)
@@ -420,7 +423,10 @@ public: @@ -420,7 +423,10 @@ public:
420 ~ShowTransform() 423 ~ShowTransform()
421 { 424 {
422 delete displayBuffer; 425 delete displayBuffer;
423 - delete window; 426 + if (QThread::currentThread() == QCoreApplication::instance()->thread())
  427 + delete window;
  428 + else
  429 + emit destroyWindow();
424 } 430 }
425 431
426 void train(const TemplateList &data) { (void) data; } 432 void train(const TemplateList &data) { (void) data; }
@@ -494,6 +500,7 @@ public: @@ -494,6 +500,7 @@ public:
494 connect(this, SIGNAL(updateImage(QPixmap)), window,SLOT(showImage(QPixmap))); 500 connect(this, SIGNAL(updateImage(QPixmap)), window,SLOT(showImage(QPixmap)));
495 connect(this, SIGNAL(changeTitle(QString)), window, SLOT(setWindowTitle(QString))); 501 connect(this, SIGNAL(changeTitle(QString)), window, SLOT(setWindowTitle(QString)));
496 connect(this, SIGNAL(hideWindow()), window, SLOT(hide())); 502 connect(this, SIGNAL(hideWindow()), window, SLOT(hide()));
  503 + connect(this, SIGNAL(destroyWindow()), window, SLOT(deleteLater()), Qt::BlockingQueuedConnection);
497 } 504 }
498 505
499 protected: 506 protected:
@@ -506,6 +513,7 @@ signals: @@ -506,6 +513,7 @@ signals:
506 void updateImage(const QPixmap & input); 513 void updateImage(const QPixmap & input);
507 void changeTitle(const QString & input); 514 void changeTitle(const QString & input);
508 void hideWindow(); 515 void hideWindow();
  516 + void destroyWindow();
509 }; 517 };
510 BR_REGISTER(Transform, ShowTransform) 518 BR_REGISTER(Transform, ShowTransform)
511 519