Skip to content

Commit

Permalink
UI: Defer startup OBSBasic::Load (macOS CEF workaround)
Browse files Browse the repository at this point in the history
Adds an alternative means of isolating the CEF initialization process
from Qt's initialization process.  This is an unpleasant hack, but is
far more preferable than isolating the entire browser plugin to a
separate process and overly complexifying the browser plugin to the
point to where no one wants to touch the plugin or contribute to it.
  • Loading branch information
jp9000 committed Apr 12, 2018
1 parent 439b9e4 commit 34c1482
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
40 changes: 33 additions & 7 deletions UI/window-basic-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1533,13 +1533,6 @@ void OBSBasic::OBSInit()
SET_VISIBILITY("ShowStatusBar", toggleStatusBar);
#undef SET_VISIBILITY

{
ProfileScope("OBSBasic::Load");
disableSaving--;
Load(savePath);
disableSaving++;
}

TimedCheckForUpdates();
loaded = true;

Expand Down Expand Up @@ -1677,6 +1670,39 @@ void OBSBasic::OBSInit()
ui->menuCrashLogs = nullptr;
ui->actionCheckForUpdates = nullptr;
#endif

/* This is an incredibly unpleasant hack for macOS to isolate CEF
* initialization until after all tasks related to Qt startup and main
* window initialization have completed. There is a macOS-specific bug
* within either CEF and/or Qt that can cause a crash if both Qt and
* CEF are loading at the same time.
*
* CEF will typically load fine after about two iterations from this
* point, and all Qt tasks are typically fully completed after about
* four or five iterations, but to be "ultra" safe, an arbitrarily
* large number such as 10 is used. This hack is extremely unpleasant,
* but is worth doing instead of being forced to isolate the entire
* browser plugin in to a separate process as before.
*
* Again, this hack is specific to macOS only. Fortunately, on other
* operating systems, such issues do not occur. */
QMetaObject::invokeMethod(this, "DeferredLoad",
Qt::QueuedConnection,
Q_ARG(QString, QT_UTF8(savePath)),
Q_ARG(int, 10));
}

void OBSBasic::DeferredLoad(const QString &file, int requeueCount)
{
if (--requeueCount > 0) {
QMetaObject::invokeMethod(this, "DeferredLoad",
Qt::QueuedConnection,
Q_ARG(QString, file),
Q_ARG(int, requeueCount));
return;
}

Load(QT_TO_UTF8(file));
}

void OBSBasic::UpdateMultiviewProjectorMenu()
Expand Down
2 changes: 2 additions & 0 deletions UI/window-basic-main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,8 @@ private slots:
void OpenMultiviewWindow();
void OpenSceneWindow();

void DeferredLoad(const QString &file, int requeueCount);

public slots:
void on_actionResetTransform_triggered();

Expand Down

0 comments on commit 34c1482

Please sign in to comment.