Closed Chetic closed 3 years ago
I came here after encountering the same issue, I have reproduced the crash using the "hello world" example for the piston game engine. More details on my particular reproduction steps here: https://github.com/PistonDevelopers/piston-examples/issues/464
A recent change seems to have caused glutin_window
to start crashing in a reproducible manner. Piston's "hello world" example definitely used to work without glutin crashing - now it crashes.
Perhaps a change in the standard library behavior(s) in Rust 1.48 versus 1.47?
The problem appears to be here
impl OpenGLWindow for GlutinWindow {
fn get_proc_address(&mut self, proc_name: &str) -> ProcAddress {
self.ctx.get_proc_address(proc_name) as *const _
}
fn is_current(&self) -> bool {
self.ctx.is_current()
}
fn make_current(&mut self) {
use std::mem::{replace, zeroed, forget};
#[allow(invalid_value)]
let ctx = replace(&mut self.ctx, unsafe{zeroed()});
forget(replace(&mut self.ctx, unsafe {ctx.make_current().unwrap()}));
}
}
Apparently, calling std::mem:zeroed()
to generate a zero initialized instance of glutin::ContextWrapper<glutin::PossiblyCurrent, glutin::Window>
is undefined behavior. This is probably because it contains function references or some other "non-nullable" type.
This very simple project crashes on startup when using Rust 1.48.0 but not 1.47.0: https://github.com/Chetic/rustler
Could be related to a compatibility change in Rust 1.48.0 (the first one): https://github.com/rust-lang/rust/blob/1.48.0/RELEASES.md#compatibility-notes Suspect function in glutin_window: https://github.com/PistonDevelopers/glutin_window/blob/master/src/lib.rs#L535