Closed fralonra closed 2 years ago
At last, I did something like this:
fn main_loop(mut surface: GlutinSurface, el: event_loop::EventLoop<()>) {
// remove the following line.
// let ctx = unsafe { surface.ctx.make_current().unwrap() };
// ...
el.run(move |event, _, control_flow| match event {
Event::RedrawRequested(_) => {
// rendering code.
// changing code to these:
let ctx = &surface.ctx;
ctx.window().request_redraw();
}
_ => (),
}
);
}
It somehow worked.
But I still wonder what is the typical solution to this problem.
I believe you are getting the error because surface.ctx.make_current()
will move the inner context out. Then inside the event loop you are trying to use surface
which has been partially moved. Instead, try calling ctx.swap_buffers()
.
You definitely don't want to leave out the line which makes the context current, though it looks like maybe it makes it current for you on creation if it's working without that line.
I believe you are getting the error because
surface.ctx.make_current()
will move the inner context out. Then inside the event loop you are trying to usesurface
which has been partially moved. Instead, try callingctx.swap_buffers()
.You definitely don't want to leave out the line which makes the context current, though it looks like maybe it makes it current for you on creation if it's working without that line.
@geom3trik Thanks for your reply!
ctx.swap_buffers
is convenient but in this pattern there are still some problems. The final working code piece looks like these:
fn main_loop(mut surface: GlutinSurface, el: event_loop::EventLoop<()>) {
// ...
el.run(move |event, _, control_flow| match event {
Event::RedrawRequested(_) => {
let back_buffer = &surface.back_buffer().unwrap();
let render = surface
.new_pipeline_gate()
.pipeline(
&back_buffer,
&PipelineState::default(),
|_, _| Ok(()), // rendering here...
)
.assume();
if render.is_ok() {
surface.swap_buffers();
}
// changing code to these:
let ctx = &surface.ctx;
ctx.window().request_redraw();
}
_ => (),
}
);
}
If I keep the code that makes the context current, an error would thrown as it conflicts with both the code to get back buffer and the pipeline gate.
Hi, thanks for this awesome library.
I'm a newbie to Rust, and have problems on how to make use of
glutin:WindowedContext
alone withluminance-glutin
crate.Below is the minimum code:
However, the code gave me the following error:
borrow of partially moved value: surface
and I've no idea how to correct it.I need
GlutinSurface
to be used in some GL stuff andglutin:WindowedContext
to handle glutin things as well.Is there anyone can help me with this? Thanks!