Hey I've been trying to build a simple gui application using minifb but couldn't help but notice, that it a draws ungodly amounts of ram and segfaults the moment I use a RefCell to manage the window with respect to ownership. This very primitive setup draws roughly 70-90 MB. I'm running this code on MacBook M2 Air with rustc 1.80.0 (051478957 2024-07-21) and minifb version minifb = "0.27.0".
use image::window::initialize;
use minifb::Window;
fn main() {
let mut window: Window = initialize("Test", 1080, 720).unwrap();
let buffer: Vec<u32> = vec![0xFF000000; 1080 * 720];
while window.is_open() {
window.update_with_buffer(&buffer, 1080, 720);
}
}
The following setup will cause a bus error. I assume it's likely due to some memory misalignment on minifb's part when having the window wrapped in a RefCell.
use image::{canvas::Canvas, window::initialize};
use minifb::Window;
use std::{borrow::BorrowMut, cell::RefCell};
fn main() {
let window: Window = initialize("Test", 1080, 720).unwrap();
let window: RefCell<Window> = RefCell::new(window);
let mut canvas: Canvas = Canvas::new(&window);
while window.borrow().is_open() {
if let Err(err) = canvas.borrow_mut().draw() {
eprintln!("[WINDOW ERROR]: {err}");
std::process::exit(-2);
}
}
}
Hey I've been trying to build a simple gui application using minifb but couldn't help but notice, that it a draws ungodly amounts of ram and segfaults the moment I use a RefCell to manage the window with respect to ownership. This very primitive setup draws roughly 70-90 MB. I'm running this code on MacBook M2 Air with
rustc 1.80.0 (051478957 2024-07-21)
and minifb versionminifb = "0.27.0"
.The following setup will cause a bus error. I assume it's likely due to some memory misalignment on minifb's part when having the window wrapped in a RefCell.
This is the code for my Canvas
Here's a quick screenshot of my, in my opinion very high ram consumption.