From b930b255c9a3d791832056604d3cb0e67236f8a3 Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 20 Jun 2017 10:46:18 +0100 Subject: [PATCH] Don't close the live capture while a menu might still be open. --- qrenderdoc/Windows/Dialogs/LiveCapture.cpp | 24 ++++++++++++++++++++-- qrenderdoc/Windows/Dialogs/LiveCapture.h | 5 +++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/qrenderdoc/Windows/Dialogs/LiveCapture.cpp b/qrenderdoc/Windows/Dialogs/LiveCapture.cpp index 1dd7340f0..32c015095 100644 --- a/qrenderdoc/Windows/Dialogs/LiveCapture.cpp +++ b/qrenderdoc/Windows/Dialogs/LiveCapture.cpp @@ -239,7 +239,9 @@ void LiveCapture::on_captures_mouseClicked(QMouseEvent *e) QObject::connect(&contextDeleteAction, &QAction::triggered, this, &LiveCapture::deleteCapture_triggered); + m_ContextMenu = &contextMenu; RDDialog::show(&contextMenu, QCursor::pos()); + m_ContextMenu = NULL; } } @@ -961,7 +963,7 @@ void LiveCapture::connectionClosed() // then don't close just yet. if(ui->captures->count() == 1 || m_Children.count() == 0) { - ToolWindowManager::closeToolWindow(this); + selfClose(); return; } @@ -973,12 +975,30 @@ void LiveCapture::connectionClosed() LiveCapture *live = new LiveCapture(m_Ctx, m_Hostname, m_HostFriendlyname, m_Children[0].ident, m_Main); m_Main->ShowLiveCapture(live); - ToolWindowManager::closeToolWindow(this); + selfClose(); return; } } } +void LiveCapture::selfClose() +{ + if(m_ContextMenu) + { + qInfo() << "preventing race"; + // hide the menu and close our window shortly after + m_ContextMenu->close(); + QTimer *timer = new QTimer(this); + QObject::connect(timer, &QTimer::timeout, [this]() { ToolWindowManager::closeToolWindow(this); }); + timer->setSingleShot(true); + timer->start(250); + } + else + { + ToolWindowManager::closeToolWindow(this); + } +} + void LiveCapture::connectionThreadEntry() { m_Connection = RENDERDOC_CreateTargetControl(m_Hostname.toUtf8().data(), m_RemoteIdent, diff --git a/qrenderdoc/Windows/Dialogs/LiveCapture.h b/qrenderdoc/Windows/Dialogs/LiveCapture.h index f42f56687..9467442d1 100644 --- a/qrenderdoc/Windows/Dialogs/LiveCapture.h +++ b/qrenderdoc/Windows/Dialogs/LiveCapture.h @@ -125,6 +125,9 @@ private: const rdctype::array &thumbnail, int32_t thumbWidth, int32_t thumbHeight, QDateTime timestamp, const QString &path, bool local); void connectionClosed(); + + void selfClose(); + void killThread(); void setTitle(const QString &title); @@ -157,6 +160,8 @@ private: bool m_IgnoreThreadClosed = false; bool m_IgnorePreviewToggle = false; + QMenu *m_ContextMenu = NULL; + QAction *previewToggle; QToolButton *openButton; QAction *newWindowAction;