I think I might have missed something about rust scoping, but I am very confused.
I thought that the below code snippets would behave exactly the same, except that in the second, the _window
variable is in its own scope (which really shouldn't matter because it is never used):
let _window = WindowBuilder::new()
.with_title("Mouse Wheel events")
.build(&event_loop)
.unwrap();
{
let _window = WindowBuilder::new()
.with_title("Mouse Wheel events")
.build(&event_loop)
.unwrap();
}
This is my full example using winit = "0.25"
:
use winit::{event::{Event, WindowEvent}, event_loop::{ControlFlow, EventLoop}, window::WindowBuilder};
fn main() {
let event_loop = EventLoop::new();
//{
let _window = WindowBuilder::new()
.with_title("Mouse Wheel events")
.build(&event_loop)
.unwrap();
//}
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
match event {
Event::WindowEvent { event, .. } => match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
_ => (),
},
_ => (),
}
});
}
Why does the window crash, if the curly braces are commented back in?