Skip to content

Commit

Permalink
Replace mem::zeroed() in AllocatorCreateInfo::default()
Browse files Browse the repository at this point in the history
Nightly rust has now turned the mem::zeroed warning into a runtime
panic.

Fixes gwihlidal#19
  • Loading branch information
aloucks committed Sep 30, 2020
1 parent e2459a4 commit a813a91
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern crate failure;
pub mod error;
pub mod ffi;
pub use crate::error::{Error, ErrorKind, Result};
use ash::vk::Handle;
use ash::{version::InstanceV1_0, vk::Handle};
use std::mem;

/// Main allocator object
Expand Down Expand Up @@ -264,12 +264,30 @@ pub struct AllocatorCreateInfo {
}

/// Construct `AllocatorCreateInfo` with default values
///
/// Note that the default `device` and `instance` fields are filled with dummy
/// implementations that will panic if used. These fields must be overwritten.
impl Default for AllocatorCreateInfo {
fn default() -> Self {
extern "C" fn get_device_proc_addr(
_: ash::vk::Instance,
_: *const std::os::raw::c_char,
) -> *const std::os::raw::c_void {
std::ptr::null()
}
extern "C" fn get_instance_proc_addr(
_: ash::vk::Instance,
name: *const std::os::raw::c_char,
) -> *const std::os::raw::c_void {
get_device_proc_addr as *const _
}
let static_fn = ash::vk::StaticFn::load(|_| get_instance_proc_addr as *const _);
let instance = unsafe { ash::Instance::load(&static_fn, ash::vk::Instance::null()) };
let device = unsafe { ash::Device::load(&instance.fp_v1_0(), ash::vk::Device::null()) };
AllocatorCreateInfo {
physical_device: ash::vk::PhysicalDevice::null(),
device: unsafe { mem::zeroed() },
instance: unsafe { mem::zeroed() },
device,
instance,
flags: AllocatorCreateFlags::NONE,
preferred_large_heap_block_size: 0,
frame_in_use_count: 0,
Expand Down
5 changes: 5 additions & 0 deletions tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ fn create_allocator() {
let _ = harness.create_allocator();
}

#[test]
fn default_allocator_create_info() {
let _ = vk_mem::AllocatorCreateInfo::default();
}

#[test]
fn create_gpu_buffer() {
let harness = TestHarness::new();
Expand Down

0 comments on commit a813a91

Please sign in to comment.