Destroy memory allocator before device

This commit is contained in:
hodasemi 2023-05-12 09:16:50 +02:00
parent abc8c6ccfc
commit 102fc3499f
2 changed files with 19 additions and 3 deletions

View file

@ -115,6 +115,7 @@ impl AllocatorBuilder {
if result == VK_SUCCESS {
Ok(Allocator {
allocator: unsafe { allocator.assume_init() },
destroyed: false,
})
} else {
Err(anyhow::Error::msg(format!(
@ -143,14 +144,20 @@ impl Default for AllocatorBuilder {
#[derive(Debug, Clone)]
pub struct Allocator {
allocator: VmaAllocator,
destroyed: bool,
}
impl Allocator {
pub fn allocate(&self) -> AllocationBuilder {
debug_assert!(!self.destroyed);
AllocationBuilder::new(self.allocator)
}
pub fn statistics(&self) -> VmaStats {
debug_assert!(!self.destroyed);
let mut stats = MaybeUninit::uninit();
unsafe {
@ -159,6 +166,16 @@ impl Allocator {
stats.assume_init()
}
}
pub fn destroy(&mut self) {
if !self.destroyed {
unsafe {
vmaDestroyAllocator(self.allocator);
}
self.destroyed = true;
}
}
}
unsafe impl Send for Allocator {}
@ -172,8 +189,6 @@ impl Allocator {
impl Drop for Allocator {
fn drop(&mut self) {
unsafe {
vmaDestroyAllocator(self.allocator);
}
self.destroy()
}
}

View file

@ -459,6 +459,7 @@ impl Drop for Device {
.clear(self);
}
self.memory_allocator.destroy();
self.destroy_device();
}
}