Skip to content

Commit

Permalink
Hack to prevent back-to-back playground tests from hanging (flutter#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdero authored and dnfield committed Apr 27, 2022
1 parent 24e249a commit 9c3cbf8
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions impeller/playground/playground.mm
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,29 @@ static void PlaygroundKeyCallback(GLFWwindow* window,
ImGui::StyleColorsDark();
ImGui::GetIO().IniFilename = nullptr;

if (::glfwInit() != GLFW_TRUE) {
return false;
// This guard is a hack to work around a problem where glfwCreateWindow
// hangs when opening a second window after GLFW has been reinitialized (for
// example, when flipping through multiple playground tests).
//
// Explanation:
// * glfwCreateWindow calls [NSApp run], which begins running the event loop
// on the current thread.
// * GLFW then immediately stops the loop when applicationDidFinishLaunching
// is fired.
// * applicationDidFinishLaunching is only ever fired once during the
// application's lifetime, so subsequent calls to [NSApp run] will always
// hang with this setup.
// * glfwInit resets the flag that guards against [NSApp run] being
// called a second time, which causes the subsequent `glfwCreateWindow` to
// hang indefinitely in the event loop, because
// applicationDidFinishLaunching is never fired.
static bool first_run = true;
if (first_run) {
first_run = false;
if (::glfwInit() != GLFW_TRUE) {
return false;
}
}
fml::ScopedCleanupClosure terminate([]() { ::glfwTerminate(); });

::glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);

Expand Down

0 comments on commit 9c3cbf8

Please sign in to comment.