From b030ae5bd7861cbf16702ea1842fa4ab780c3b2d Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 20 Nov 2017 18:21:09 +0000 Subject: [PATCH] Fix possible crash with pixel history if window is closed early --- qrenderdoc/Windows/TextureViewer.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/qrenderdoc/Windows/TextureViewer.cpp b/qrenderdoc/Windows/TextureViewer.cpp index 0e142b2f3..608ac2cf2 100644 --- a/qrenderdoc/Windows/TextureViewer.cpp +++ b/qrenderdoc/Windows/TextureViewer.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include "3rdparty/flowlayout/FlowLayout.h" #include "3rdparty/toolwindowmanager/ToolWindowManagerArea.h" @@ -3425,16 +3426,23 @@ void TextureViewer::on_pixelHistory_clicked() m_Ctx.AddDockWindow(hist->Widget(), DockReference::RightOf, this, 0.3f); + // we use this pointer to ensure that the history viewer is still visible (and hasn't been closed) + // by the time we want to set the results. + QPointer histWidget = hist->Widget(); + // add a short delay so that controls repainting after a new panel appears can get at the // render thread before we insert the long blocking pixel history task - LambdaThread *thread = new LambdaThread([this, texptr, x, y, hist]() { + LambdaThread *thread = new LambdaThread([this, texptr, x, y, hist, histWidget]() { QThread::msleep(150); - m_Ctx.Replay().AsyncInvoke([this, texptr, x, y, hist](IReplayController *r) { + m_Ctx.Replay().AsyncInvoke([this, texptr, x, y, hist, histWidget](IReplayController *r) { rdcarray history = r->PixelHistory(texptr->ID, (uint32_t)x, (int32_t)y, m_TexDisplay.sliceFace, m_TexDisplay.mip, m_TexDisplay.sampleIdx, m_TexDisplay.typeHint); - GUIInvoke::call([hist, history] { hist->SetHistory(history); }); + GUIInvoke::call([hist, histWidget, history] { + if(histWidget) + hist->SetHistory(history); + }); }); }); thread->selfDelete(true);