From 775fee6b6ae42498c23fb888a338960a1844dd73 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Wed, 20 Apr 2022 20:56:15 +0000 Subject: [PATCH] Check GLFW window creation before discovering GL adapters GLFW window creation can fail. If so, we should not attempt to make the context current and create adapters on it. Bug: dawn:1375 Change-Id: Ie1a94a42d1f56514b41a715add7a2b4eebb763f0 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87460 Reviewed-by: Loko Kung Commit-Queue: Austin Eng --- src/dawn/tests/DawnTest.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/dawn/tests/DawnTest.cpp b/src/dawn/tests/DawnTest.cpp index 708fb5f1e6..9dda7f2a9a 100644 --- a/src/dawn/tests/DawnTest.cpp +++ b/src/dawn/tests/DawnTest.cpp @@ -429,11 +429,12 @@ std::unique_ptr DawnTestEnvironment::CreateInstanceAndDi glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); mOpenGLWindow = glfwCreateWindow(400, 400, "Dawn OpenGL test window", nullptr, nullptr); - - glfwMakeContextCurrent(mOpenGLWindow); - dawn::native::opengl::AdapterDiscoveryOptions adapterOptions; - adapterOptions.getProc = reinterpret_cast(glfwGetProcAddress); - instance->DiscoverAdapters(&adapterOptions); + if (mOpenGLWindow != nullptr) { + glfwMakeContextCurrent(mOpenGLWindow); + dawn::native::opengl::AdapterDiscoveryOptions adapterOptions; + adapterOptions.getProc = reinterpret_cast(glfwGetProcAddress); + instance->DiscoverAdapters(&adapterOptions); + } #endif // DAWN_ENABLE_BACKEND_DESKTOP_GL #ifdef DAWN_ENABLE_BACKEND_OPENGLES @@ -454,12 +455,13 @@ std::unique_ptr DawnTestEnvironment::CreateInstanceAndDi glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); mOpenGLESWindow = glfwCreateWindow(400, 400, "Dawn OpenGLES test window", nullptr, nullptr); - - glfwMakeContextCurrent(mOpenGLESWindow); - dawn::native::opengl::AdapterDiscoveryOptionsES adapterOptionsES; - adapterOptionsES.getProc = reinterpret_cast(glfwGetProcAddress); - instance->DiscoverAdapters(&adapterOptionsES); - glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE); + if (mOpenGLESWindow != nullptr) { + glfwMakeContextCurrent(mOpenGLESWindow); + dawn::native::opengl::AdapterDiscoveryOptionsES adapterOptionsES; + adapterOptionsES.getProc = reinterpret_cast(glfwGetProcAddress); + instance->DiscoverAdapters(&adapterOptionsES); + glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE); + } #endif // DAWN_ENABLE_BACKEND_OPENGLES return instance;