error[E0521]: borrowed data escapes outside of closure
--> rend3-egui/src/lib.rs:75:25
|
74 | builder.build(move |mut ctx| {
| -------
| |
| `ctx` is a reference that is only valid in the closure body
| has type `NodeExecutionContext<'_, '1, '_>`
75 | let rpass = ctx.encoder_or_pass.take_rpass(rpass_handle);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| `ctx` escapes the closure body here
| argument requires that `'1` must outlive `'static`
|
= note: requirement occurs because of a mutable reference to `RenderGraphEncoderOrPass<'_, '_>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
This is an unusual variation of a common problem. This code used to work. The project is at
and branch "trunk" will compile. But branch "wgpu22", which is mostly changes to dependencies to upgrade "wgpu", "egui", etc. gets the error above. The code with the compile error is the same in both branches.
It seems to be the upgrade to "egui" which caused the problem.
But, in both versions, Context (the type of ctx) is
Note that the lifetime of render_pass is 'static which requires a call to [wgpu::RenderPass::forget_lifetime]. This allows users to pass resources that live outside of the callback resources to the render pass. The render pass internally keeps all referenced resources alive as long as necessary. The only consequence of forget_lifetime is that any operation on the parent encoder will cause a runtime error instead of a compile time error.
Right. Inference from the code down at .render below the lines in the error message implied a lifetime constraint at take_rpass. The error message doesn't show where the inference comes from. That's whats's wrong. And it will be a major effort to fix.
The rend3 crate has its own homebrew object system, built with closures and enums. The RenderGraphEncoderOrPass enum can contain either an encoder or a render pass struct. The WGPU people changed the lifetime of RenderPass but not Encoder, the two enum options.
That breaks code handling both types via the enum. All the code which does that needs to change.