Skip to content

Commit

Permalink
window: fix potential crash with multiple egl windows on windows
Browse files Browse the repository at this point in the history
I didn't actually see this crash, but the same potential problem
was present, so adjust the code as per 9712d4d

refs: #316
  • Loading branch information
wez committed Nov 1, 2020
1 parent 9712d4d commit 403d002
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions window/src/os/windows/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
})
}

Expand Down
11 changes: 10 additions & 1 deletion window/src/os/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 403d002

Please sign in to comment.