Skip to content

Commit

Permalink
Delay modal dialogs until next event loop iteration
Browse files Browse the repository at this point in the history
Showing a modal dialog with its own event loop while painting a GL view
can break the rendering state. This commits changes two dialogs that
could potentially pop up during rendering so that they are only shown in
the next iteration of the event loop, outside of painting.
  • Loading branch information
kduske committed Jan 23, 2023
1 parent a5784f5 commit 908be21
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions common/src/PreferenceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <QMessageBox>
#include <QStandardPaths>
#include <QStringBuilder>
#include <QTimer>

#include <string>
#include <vector>
Expand Down Expand Up @@ -427,9 +428,11 @@ void AppPreferenceManager::showErrorAndDisableFileReadWrite(
.arg(m_preferencesFilePath)
.arg(suggestion);

auto dialog =
QMessageBox(QMessageBox::Icon::Critical, tr("TrenchBroom"), message, QMessageBox::Ok);
dialog.exec();
QTimer::singleShot(0, [=] {
auto dialog = QMessageBox(
QMessageBox::Icon::Critical, tr("TrenchBroom"), message, QMessageBox::Ok);
dialog.exec();
});
}

/**
Expand Down
4 changes: 3 additions & 1 deletion common/src/TrenchBroomApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,9 @@ bool TrenchBroomApp::recoverFromException(
}
else
{
QMessageBox::critical(nullptr, "TrenchBroom", e.what(), QMessageBox::Ok);
QTimer::singleShot(0, [message = e.what()] {
QMessageBox::critical(nullptr, "TrenchBroom", message, QMessageBox::Ok);
});
return false;
}
}
Expand Down

0 comments on commit 908be21

Please sign in to comment.