This repository was archived by the owner on Oct 28, 2025. It is now read-only.
Open
Conversation
|
You need to change drop implementation here. I hacked this tutorial a bit ago and finished with this destructor which doesn't segfaults. impl<B: gfx_hal::Backend> Drop for ResourceHolder<B> {
fn drop(&mut self) {
use gfx_hal::device::Device;
use gfx_hal::window::PresentationSurface;
use gfx_hal::Instance;
// Saving instance because double free or something like this
// occurs if it dropped before other fields.
let _instance = unsafe {
// We are moving the `Resources` out of the struct...
let Resources {
instance,
mut surface,
device,
command_pool,
render_passes,
pipeline_layouts,
pipelines,
submission_complete_fence,
rendering_complete_semaphore,
// This things dropped automatically but PRIOR to instance.
command_buffer: _command_buffer,
adapter: _adapter,
queue_group: _queue_group,
surface_color_format: _surface_color_format,
surface_extent: _surface_extent,
} = ManuallyDrop::take(&mut self.res);
// ... and destroying them individually:
device.destroy_semaphore(rendering_complete_semaphore);
device.destroy_fence(submission_complete_fence);
for pipeline in pipelines {
device.destroy_graphics_pipeline(pipeline);
}
for pipeline_layout in pipeline_layouts {
device.destroy_pipeline_layout(pipeline_layout);
}
for render_pass in render_passes {
device.destroy_render_pass(render_pass);
}
device.destroy_command_pool(command_pool);
surface.unconfigure_swapchain(&device);
instance.destroy_surface(surface);
instance
};
}
}As you see, you need drop everything prior to instance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks a lot for your tutorial!
gfx-hal 0.7has been released and I would like to learn the newest API. I could not find any tutorial dealing with the 0.7 branch specifically. So I tried to upgrade your tutorial code.Warning: ! This is mostly a bunch of monkey patching and me not knowing what I'm doing ! I just experimented and took inspiration from the examples in the
gfx-halrepository. This compiles and runs on Linux (vulkan backend). But it segfaults on exit, so the upgrade is definitely not correct!I don't think this should be merged as is. Or maybe never. But it can help others who come here also looking for gfx-hal 0.7 code. And if you would like to upgrade your tutorial, this might be a start(?). Also, if you want to, I'd love feedback on where I'm screwing up the upgrade :)