Destroy memory allocator before device
This commit is contained in:
parent
abc8c6ccfc
commit
102fc3499f
2 changed files with 19 additions and 3 deletions
|
@ -115,6 +115,7 @@ impl AllocatorBuilder {
|
||||||
if result == VK_SUCCESS {
|
if result == VK_SUCCESS {
|
||||||
Ok(Allocator {
|
Ok(Allocator {
|
||||||
allocator: unsafe { allocator.assume_init() },
|
allocator: unsafe { allocator.assume_init() },
|
||||||
|
destroyed: false,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Err(anyhow::Error::msg(format!(
|
Err(anyhow::Error::msg(format!(
|
||||||
|
@ -143,14 +144,20 @@ impl Default for AllocatorBuilder {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Allocator {
|
pub struct Allocator {
|
||||||
allocator: VmaAllocator,
|
allocator: VmaAllocator,
|
||||||
|
|
||||||
|
destroyed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Allocator {
|
impl Allocator {
|
||||||
pub fn allocate(&self) -> AllocationBuilder {
|
pub fn allocate(&self) -> AllocationBuilder {
|
||||||
|
debug_assert!(!self.destroyed);
|
||||||
|
|
||||||
AllocationBuilder::new(self.allocator)
|
AllocationBuilder::new(self.allocator)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn statistics(&self) -> VmaStats {
|
pub fn statistics(&self) -> VmaStats {
|
||||||
|
debug_assert!(!self.destroyed);
|
||||||
|
|
||||||
let mut stats = MaybeUninit::uninit();
|
let mut stats = MaybeUninit::uninit();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -159,6 +166,16 @@ impl Allocator {
|
||||||
stats.assume_init()
|
stats.assume_init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn destroy(&mut self) {
|
||||||
|
if !self.destroyed {
|
||||||
|
unsafe {
|
||||||
|
vmaDestroyAllocator(self.allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.destroyed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl Send for Allocator {}
|
unsafe impl Send for Allocator {}
|
||||||
|
@ -172,8 +189,6 @@ impl Allocator {
|
||||||
|
|
||||||
impl Drop for Allocator {
|
impl Drop for Allocator {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
self.destroy()
|
||||||
vmaDestroyAllocator(self.allocator);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -459,6 +459,7 @@ impl Drop for Device {
|
||||||
.clear(self);
|
.clear(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.memory_allocator.destroy();
|
||||||
self.destroy_device();
|
self.destroy_device();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue