macOS crash fix attempt
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -82,7 +82,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "baseview"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/RustAudio/baseview#f7326ceab58c8dd75f3e10bc815ecf7d098e2efc"
|
||||
source = "git+https://github.com/RustAudio/baseview?rev=237d323c729f3aa99476ba3efa50129c5e86cad3#237d323c729f3aa99476ba3efa50129c5e86cad3"
|
||||
dependencies = [
|
||||
"cocoa",
|
||||
"core-foundation",
|
||||
|
||||
@@ -10,7 +10,7 @@ crate-type = ["cdylib"]
|
||||
ebu-dsp = { version = "0.1.0", path = "ebu-dsp" }
|
||||
nih_plug = { git = "https://github.com/robbert-vdh/nih-plug", version = "0.0.0", default-features = false }
|
||||
parking_lot = "0.12.5"
|
||||
baseview = { git = "https://github.com/RustAudio/baseview", version = "0.1.0", features = ["opengl"]}
|
||||
baseview = { git = "https://github.com/RustAudio/baseview", rev = "237d323c729f3aa99476ba3efa50129c5e86cad3", features = ["opengl"]}
|
||||
crossbeam = "0.8.4"
|
||||
femtovg = "0.18.1"
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
|
||||
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();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::sync::{Arc, atomic::Ordering};
|
||||
use baseview::{Window, WindowOpenOptions, WindowScalePolicy, gl::GlConfig};
|
||||
use crossbeam::atomic::AtomicCell;
|
||||
use nih_plug::{editor::Editor, plugin::Plugin};
|
||||
use nih_plug::{editor::Editor, nih_error, plugin::Plugin};
|
||||
use crate::{AirFreshener, editor::EditorHandle, parameters::PluginParams, gui::PluginGui};
|
||||
|
||||
pub struct EditorWindow {
|
||||
@@ -49,7 +49,10 @@ impl Editor for EditorWindow {
|
||||
..Default::default()
|
||||
})
|
||||
}, move |window: &mut baseview::Window<'_>| -> PluginGui {
|
||||
PluginGui::new(window, gui_context, params, scaling_factor.unwrap_or(1.0))
|
||||
match PluginGui::new(window, gui_context, params, scaling_factor.unwrap_or(1.0)) {
|
||||
Err(err) => { nih_error!("Failed to create plugin: {err}"); panic!("{err}"); }
|
||||
Ok(plug) => plug
|
||||
}
|
||||
});
|
||||
self.params.editor_state.open.store(true, Ordering::Release);
|
||||
Box::new(EditorHandle {
|
||||
|
||||
Reference in New Issue
Block a user