Fixed deadlock on start with recent Qt versions

This commit is contained in:
ksuprynowicz 2023-04-10 18:22:52 +02:00
parent 8b9cd84df7
commit 28079eb2df
2 changed files with 18 additions and 1 deletions

View file

@ -977,6 +977,12 @@ QSharedPointer<OffscreenUi> getOffscreenUI() {
#endif
}
bool Application::initMenu() {
_isMenuInitialized = false;
qApp->getWindow()->menuBar();
return true;
}
Application::Application(
int& argc, char** argv,
const QCommandLineParser& parser,
@ -985,6 +991,8 @@ Application::Application(
) :
QApplication(argc, argv),
_window(new MainWindow(desktop())),
// Menu needs to be initialized before other initializers. Otherwise deadlock happens on qApp->getWindow()->menuBar().
_isMenuInitialized(initMenu()),
_sessionRunTimer(startupTimer),
#ifndef Q_OS_ANDROID
_logger(new FileLogger(this)),
@ -1017,7 +1025,6 @@ Application::Application(
_snapshotSound(nullptr),
_sampleSound(nullptr)
{
auto steamClient = PluginManager::getInstance()->getSteamClientPlugin();
setProperty(hifi::properties::STEAM, (steamClient && steamClient->isRunning()));
setProperty(hifi::properties::CRASHED, _previousSessionCrashed);
@ -4225,6 +4232,11 @@ bool Application::event(QEvent* event) {
return false;
}
// This helps avoid deadlock issue early during Application initialization
if (!_isMenuInitialized) {
return QApplication::event(event);
}
if (!Menu::getInstance()) {
return false;
}

View file

@ -562,6 +562,7 @@ private slots:
private:
void init();
bool initMenu();
void pauseUntilLoginDetermined();
void resumeAfterLoginDialogActionTaken();
bool handleKeyEventForFocusedEntity(QEvent* event);
@ -626,6 +627,10 @@ private:
void userKickConfirmation(const QUuid& nodeID, unsigned int banFlags = ModerationFlags::getDefaultBanFlags());
MainWindow* _window;
// _isMenuInitialized: used to initialize menu early enough before it's needed by other
// initializers. Fixes a deadlock issue with recent Qt versions.
bool _isMenuInitialized;
QElapsedTimer& _sessionRunTimer;
bool _aboutToQuit { false };