Skip to content

Commit

Permalink
fix: Abandon context if not current when closing the app (#355)
Browse files Browse the repository at this point in the history
* fix: Abandon context if not current when closing the app

* mock `abandon`

* fixes

* tweak
  • Loading branch information
marc2332 authored Dec 31, 2023
1 parent 37948d6 commit 0a59162
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions crates/engine/src/mocked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,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
13 changes: 12 additions & 1 deletion crates/renderer/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use freya_common::EventMessage;
use freya_core::prelude::*;
use freya_dom::prelude::FreyaDOM;
use freya_engine::prelude::*;
use glutin::prelude::{PossiblyCurrentContextGlSurfaceAccessor, PossiblyCurrentGlContext};
use std::ffi::CString;
use std::num::NonZeroU32;
use torin::geometry::{Area, Size2D};
Expand Down Expand Up @@ -34,9 +35,9 @@ use crate::HoveredNode;

/// Manager for a Window
pub struct WindowEnv<T: Clone> {
gr_context: DirectContext,
surface: Surface,
gl_surface: GlutinSurface<WindowSurface>,
gr_context: DirectContext,
gl_context: PossiblyCurrentContext,
pub(crate) window: Window,
fb_info: FramebufferInfo,
Expand All @@ -45,6 +46,16 @@ 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() {
if self.gl_context.make_current(&self.gl_surface).is_err() {
self.gr_context.abandon();
}
}
}
}

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

0 comments on commit 0a59162

Please sign in to comment.