So I have the following code: basically I'm creating a texture, creating a binder which basically holds a reference to the texture to send it to the GPU and then start the rendering loop with a "Never" return (Which is basically infinite until the program closes).
//Load texture from path.
let texture = Texture::from_path(window_view, Path::new("examples/draw_cube/UV_1k.jpg"));
let mut binder = Binder::new();
binder.set_bind(0, &texture);
binder.set_bind(1, &BinderPart::Sampler);
//Create brush to draw the shapes.
let mut brush = Brush::from_path(
window.view(),
Path::new("examples/shared_assets/basic.wgsl"#),
)?;
// Add binder information to the brush
brush.set_binder(0, binder);
...
//Setup the window render loop.
window.run(move |wnd| {
let mut frame = wnd.start_frame(None).expect("Issue creating frame.");
frame.render(wnd, &mut brush, &buffer);
frame.finish(wnd).expect("Error finishing frame.");
});
I was expecting the render loop to move the texture ownership to the loop itself but I'm getting the following errors:
error[E0597]: `texture` does not live long enough
--> examples\draw_cube\main.rs:110:24
|
110 | binder.set_bind(0, &texture);
| ^^^^^^^^ borrowed value does not live long enough
...
133 | / window.run(move |wnd| {
134 | | let mut frame = wnd.start_frame(None).expect("Issue creating frame.");
135 | | ...
136 | | frame.finish(wnd).expect("Error finishing frame.");
137 | | });
| |______- argument requires that `texture` is borrowed for `'static`
...
141 | }
| - `texture` dropped here while still borrowed
I'm not understanding ownership correctly? Do I need to hold the texture ownership in another way in order to be able to modify it inside the render loop?
Thanks!