window: fix potential crash with multiple egl windows on windows

I didn't actually see this crash, but the same potential problem
was present, so adjust the code as per 9712d4d03c

refs: #316
This commit is contained in:
Wez Furlong committed 2020-11-01 10:28:17 -08:00
1 parent 9712d4d03c
commit 403d002d0a
2 files changed
+14 -1

No files matched your search

+4
View File
@@ -18,6 +18,8 @@ pub struct Connection {
event_handle: HANDLE,
pub(crate) windows: RefCell<HashMap<HWindow, Rc<RefCell<WindowInner>>>>,
timers: RefCell<HashMap<UINT_PTR, UINT_PTR>>,
#[cfg(feature = "opengl")]
pub(crate) gl_connection: RefCell<Option<Rc<crate::egl::GlConnection>>>,
}
impl ConnectionOps for Connection {
@@ -97,6 +99,8 @@ impl Connection {
event_handle,
windows: RefCell::new(HashMap::new()),
timers: RefCell::new(HashMap::new()),
#[cfg(feature = "opengl")]
gl_connection: RefCell::new(None),
})
}
+10 -1
View File
@@ -132,14 +132,23 @@ impl WindowInner {
#[cfg(feature = "opengl")]
fn enable_opengl(&mut self) -> anyhow::Result<()> {
let window = Window(self.hwnd);
let conn = Connection::get().unwrap();
let gl_state = if is_egl_preferred() {
crate::egl::GlState::create(None, self.hwnd.0)
match conn.gl_connection.borrow().as_ref() {
None => crate::egl::GlState::create(None, self.hwnd.0),
Some(glconn) => {
crate::egl::GlState::create_with_existing_connection(glconn, self.hwnd.0)
}
}
} else {
Err(anyhow::anyhow!("Config says to avoid EGL"))
}
.and_then(|egl| unsafe {
log::error!("Initialized EGL!");
conn.gl_connection
.borrow_mut()
.replace(Rc::clone(egl.get_connection()));
let backend = Rc::new(egl);
Ok(glium::backend::Context::new(
backend,