实现drop
其实这个完全是因为现在的gfx-hal
写的差劲的原因,人家Rust
的内存管理理论上都不需要用户来管的...
impl core::ops::Drop for HardwareState {
// 我发现了个bug在这个垃圾gfx-hal里面swapchain更换的特别频繁的时候,Rust自动drop跟不上,所以这里用的手动drop
// 还有可爱的GFX开发组哟,能不能把修一修,这个unsafe看的我浑身难受
fn drop(&mut self) {
let _ = self.device.wait_idle();
unsafe {
for fence in self.in_flight_fences.drain(..) {
self.device.destroy_fence(fence)
}
for semaphore in self.render_finished_semaphores.drain(..) {
self.device.destroy_semaphore(semaphore)
}
for semaphore in self.image_available_semaphores.drain(..) {
self.device.destroy_semaphore(semaphore)
}
for framebuffer in self.framebuffers.drain(..) {
self.device.destroy_framebuffer(framebuffer);
}
for image_view in self.image_views.drain(..) {
self.device.destroy_image_view(image_view);
}
use core::ptr::read;
self.device.destroy_command_pool(
ManuallyDrop::into_inner(read(&self.command_pool)).into_raw(),
);
self.device
.destroy_render_pass(ManuallyDrop::into_inner(read(&self.render_pass)));
self.device
.destroy_swapchain(ManuallyDrop::into_inner(read(&self.swapchain)));
ManuallyDrop::drop(&mut self.device);
ManuallyDrop::drop(&mut self._instance);
}
}
}