From ab1e83c7eba04bb4a3e9003e81bef78be415ba08 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 29 Jun 2020 18:05:43 -0700 Subject: [PATCH] window: fallback to basic opengl context if extensions fail 8f1f1a65eae6b3fe57031bd7fc97a02e17087db4 added support for probing for opengl extensions, and I thought that I had the fallback covered but it turned out that we were only falling back if one of the major extensions wasn't present. This commit adds a fallback for the case where things look ok at first glance, but where they fail at runtime for whatever reason. refs: https://github.com/wez/wezterm/issues/235 --- window/src/os/windows/wgl.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/window/src/os/windows/wgl.rs b/window/src/os/windows/wgl.rs index 106f62b12..74eb8a0a2 100644 --- a/window/src/os/windows/wgl.rs +++ b/window/src/os/windows/wgl.rs @@ -167,7 +167,18 @@ impl GlState { log::trace!("opengl extensions: {:?}", extensions); if has_extension(&extensions, "WGL_ARB_pixel_format") { - return Self::create_ext(wgl, extensions, hdc); + return match Self::create_ext(wgl, extensions, hdc) { + Ok(state) => Ok(state), + Err(err) => { + log::error!( + "failed to created extended OpenGL context \ + ({}), fall back to basic", + err + ); + let wgl = WglWrapper::load()?; + Self::create_basic(wgl, window) + } + }; } } @@ -283,7 +294,7 @@ impl GlState { }; if rc.is_null() { - anyhow::bail!("failed to make context"); + anyhow::bail!("CreateContextAttribsARB failed"); } unsafe {