Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Abandon context if not current when closing the app #355

Merged
merged 5 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/engine/src/mocked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,10 @@ impl DirectContext {
pub fn flush_and_submit(&self) {
unimplemented!("This is mocked")
}

pub fn abandon(&self) {
unimplemented!("This is mocked")
}
}

use std::ffi::c_void;
Expand Down
9 changes: 9 additions & 0 deletions crates/renderer/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use freya_core::prelude::*;
use freya_dom::prelude::FreyaDOM;
use freya_engine::prelude::*;
use freya_layout::Layers;
use glutin::prelude::PossiblyCurrentGlContext;
use std::ffi::CString;
use std::num::NonZeroU32;
use torin::geometry::{Area, Size2D};
Expand Down Expand Up @@ -46,6 +47,14 @@ pub struct WindowEnv<T: Clone> {
pub(crate) window_config: WindowConfig<T>,
}

impl<T: Clone> Drop for WindowEnv<T> {
fn drop(&mut self) {
if !self.gl_context.is_current() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to try to make the context current and only abandon if making it current fails.

self.gr_context.abandon();
}
}
}

impl<T: Clone> WindowEnv<T> {
/// Create a Window environment from a set of configuration
pub fn from_config(
Expand Down