macOS crash fix attempt
This commit is contained in:
50
src/gui.rs
50
src/gui.rs
@@ -9,8 +9,7 @@ use std::sync::Arc;
|
||||
|
||||
const FRESHENER_IMAGE: &'static [u8] = include_bytes!("../assets/AirFreshener/sheet.png");
|
||||
const NOT_SO_FRESH_BG_IMAGE: &'static [u8] = include_bytes!("../assets/AirFreshener/bg0.png");
|
||||
const FRESH_DUMBLEDORE_BG_IMAGE: &'static [u8] =
|
||||
include_bytes!("../assets/AirFreshener/bg1.png");
|
||||
const FRESH_DUMBLEDORE_BG_IMAGE: &'static [u8] = include_bytes!("../assets/AirFreshener/bg1.png");
|
||||
const FRESHENER_FRAMES: u32 = 256;
|
||||
const FRESHENER_FRAMES_X: u32 = 20;
|
||||
const FRESHENER_FRAMES_Y: u32 = 13;
|
||||
@@ -43,36 +42,33 @@ impl PluginGui {
|
||||
gui_context: Arc<dyn GuiContext>,
|
||||
params: Arc<PluginParams>,
|
||||
scaling_factor: f32,
|
||||
) -> Self {
|
||||
) -> Result<Self, &'static str> {
|
||||
let context = window
|
||||
.gl_context()
|
||||
.expect("Failed to get window OpenGL context");
|
||||
.ok_or("Failed to get window OpenGL context")?;
|
||||
unsafe {
|
||||
context.make_current();
|
||||
}
|
||||
let renderer = unsafe { OpenGl::new_from_function(|s| context.get_proc_address(s)) }
|
||||
.expect("Failed to create femtovg renderer");
|
||||
let mut canvas = Canvas::new(renderer).expect("Failed to create femtovg canvas");
|
||||
.map_err(|_| "Failed to create femtovg renderer")?;
|
||||
let mut canvas = Canvas::new(renderer).map_err(|_| "Failed to create femtovg canvas")?;
|
||||
let (width, height) = params.editor_state.size();
|
||||
|
||||
canvas.set_size(width, height, scaling_factor);
|
||||
let le_fresh = canvas
|
||||
.load_image_mem(FRESHENER_IMAGE, ImageFlags::empty())
|
||||
.expect("Failed to load le fresh");
|
||||
.map_err(|_| "Failed to load le fresh")?;
|
||||
let not_so_fresh_image = canvas
|
||||
.load_image_mem(NOT_SO_FRESH_BG_IMAGE, ImageFlags::empty())
|
||||
.expect("Failed to load not so fresh");
|
||||
.map_err(|_| "Failed to load not so fresh")?;
|
||||
let fresh_dumbledore_image = canvas
|
||||
.load_image_mem(FRESH_DUMBLEDORE_BG_IMAGE, ImageFlags::empty())
|
||||
.expect("Failed to load fresh dumbledore");
|
||||
//let font = canvas
|
||||
// .add_font_mem(DROID_SANS_FONT)
|
||||
// .expect("Failed to load font");
|
||||
.map_err(|_| "Failed to load fresh dumbledore")?;
|
||||
|
||||
unsafe {
|
||||
context.make_not_current();
|
||||
}
|
||||
Self {
|
||||
Ok(Self {
|
||||
//font,
|
||||
params,
|
||||
canvas,
|
||||
@@ -92,7 +88,7 @@ impl PluginGui {
|
||||
width: FRESHENER_FRAME_WIDTH,
|
||||
height: FRESHENER_FRAME_HEIGHT,
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,9 +101,13 @@ impl WindowHandler for PluginGui {
|
||||
//return;
|
||||
}
|
||||
|
||||
let context = window
|
||||
.gl_context()
|
||||
.expect("Failed to get window OpenGL context");
|
||||
let context = match window.gl_context() {
|
||||
None => {
|
||||
nih_error!("No OpenGL context");
|
||||
return;
|
||||
}
|
||||
Some(ctx) => ctx,
|
||||
};
|
||||
unsafe {
|
||||
context.make_current();
|
||||
}
|
||||
@@ -177,22 +177,6 @@ impl WindowHandler for PluginGui {
|
||||
1.0,
|
||||
),
|
||||
);
|
||||
/*
|
||||
let debug = format!("{:#?}", self.params.comp_state.load());
|
||||
for (i, line) in debug.split('\n').enumerate() {
|
||||
self.canvas
|
||||
.fill_text(
|
||||
10.0,
|
||||
10.0 + i as f32 * 12.5,
|
||||
line,
|
||||
&Paint::color(Color::rgbf(1.0, 1.0, 1.0))
|
||||
.with_font(&[self.font])
|
||||
.with_font_size(12.5)
|
||||
.with_text_baseline(femtovg::Baseline::Top),
|
||||
)
|
||||
.expect("Failed to render font");
|
||||
}
|
||||
*/
|
||||
|
||||
self.canvas.flush();
|
||||
context.swap_buffers();
|
||||
|
||||
Reference in New Issue
Block a user