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 176 setFixedSize(200,200);
177 177 QApplication::instance()->installEventFilter(this);
178 178 }
  179 + ~DisplayWindow()
  180 + {
  181 + QApplication::instance()->removeEventFilter(this);
  182 + }
179 183  
180 184 public slots:
181 185 void showImage(const QPixmap & input)
... ... @@ -193,7 +197,6 @@ public slots:
193 197 setFixedSize(temp);
194 198 }
195 199  
196   -
197 200 bool eventFilter(QObject * obj, QEvent * event)
198 201 {
199 202 if (event->type() == QEvent::KeyPress)
... ... @@ -420,7 +423,10 @@ public:
420 423 ~ShowTransform()
421 424 {
422 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 432 void train(const TemplateList &data) { (void) data; }
... ... @@ -494,6 +500,7 @@ public:
494 500 connect(this, SIGNAL(updateImage(QPixmap)), window,SLOT(showImage(QPixmap)));
495 501 connect(this, SIGNAL(changeTitle(QString)), window, SLOT(setWindowTitle(QString)));
496 502 connect(this, SIGNAL(hideWindow()), window, SLOT(hide()));
  503 + connect(this, SIGNAL(destroyWindow()), window, SLOT(deleteLater()), Qt::BlockingQueuedConnection);
497 504 }
498 505  
499 506 protected:
... ... @@ -506,6 +513,7 @@ signals:
506 513 void updateImage(const QPixmap & input);
507 514 void changeTitle(const QString & input);
508 515 void hideWindow();
  516 + void destroyWindow();
509 517 };
510 518 BR_REGISTER(Transform, ShowTransform)
511 519  
... ...