-
Notifications
You must be signed in to change notification settings - Fork 550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems with destroy ergonomics when using it from Drop #2452
Comments
I use |
How can |
I have many thoughts on the issue, but no solution:
|
The more specific use case I'm running into is, for example, putting a rendering System in a specs World. The rendering system itself owns some graphics resources, but there's no way to entirely get back ownership to the system, or even access it again. There may be some better ways to solve this issue, perhaps this is enough of a common use case that it would make sense to have an example on it to both inform gfx and specs' design? |
A gfx-hal example with specs would indeed be helpful. Although, again, we expect most gfx-rs users to just move to wgpu-rs instead.
… On Oct 27, 2018, at 12:19, Layl ***@***.***> wrote:
The more specific use case I'm running into is, for example, putting a rendering System in a specs World. The rendering system itself owns some graphics resources, but there's no way to entirely get back ownership to the system, or even access it again.
There may be some better ways to solve this issue, perhaps this is enough of a common use case that it would make sense to have an example on it to both inform gfx and specs' design?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Personally, I really enjoy working at a low level like gfx-hal provides, while still having the benefits of easier cross-platform-native porting. This specific API issue is the main one I ran into when using gfx-hal in this way. Is there any problem with changing the API to use Alternatively, a workaround would be useful. |
@LaylConway |
@LaylConway @omni-viral please have a look at #2457 RFC |
This question also came up on Stack Overflow. One answer there shows usage of |
Using Using the "read and destroy" technique that omni-viral alluded to would look something like this: use core::ptr::read;
self.device.destroy_render_pass(ManuallyDrop::into_inner(read(&mut self.render_pass))); |
Currently, when destroying any backend structure explicitly, such as a buffer, you need to pass it by value.
These semantics make sense in principle, but in practice it makes it hard to write simple wrappers that RAII wrap around these types.
A solution is to wrap all these types in
Option
, but this quickly becomes very cumbersome just for this one specific use. Since these functions are already unsafe, why not just allow them to take&mut
?The text was updated successfully, but these errors were encountered: