diff --git a/examples/triangle/src/main.rs b/examples/triangle/src/main.rs index e655cd6..a003016 100644 --- a/examples/triangle/src/main.rs +++ b/examples/triangle/src/main.rs @@ -42,7 +42,7 @@ fn create_surface(instance: &Instance, window: x11_window as vk::Window, dpy: x11_display as *mut vk::Display, }; - let xlib_surface_loader = XlibSurface::new(&entry, &instance); + let xlib_surface_loader = XlibSurface::new(&entry, &instance).expect("Unable to load xlib surface"); xlib_surface_loader.create_xlib_surface_khr(&x11_create_info) } @@ -154,12 +154,13 @@ fn main() { pfn_callback: vulkan_debug_callback, p_user_data: ptr::null_mut(), }; - let debug_report_loader = DebugReport::new(&entry, &instance); + let debug_report_loader = DebugReport::new(&entry, &instance).expect("Unable to load debug report"); let debug_call_back = debug_report_loader.create_debug_report_callback_ext(&debug_info) .unwrap(); let surface = create_surface(&instance, &entry, &window).unwrap(); let pdevices = instance.enumerate_physical_devices().expect("Physical device error"); - let surface_loader = Surface::new(&entry, &instance); + let surface_loader = Surface::new(&entry, &instance) + .expect("Unable to load the Surface extension"); let (pdevice, queue_family_index) = pdevices.iter() .map(|pdevice| { instance.get_physical_device_queue_family_properties(*pdevice) @@ -257,7 +258,7 @@ fn main() { .cloned() .find(|&mode| mode == vk::PresentModeKHR::Mailbox) .unwrap_or(vk::PresentModeKHR::Fifo); - let swapchain_loader = Swapchain::new(&instance, &device); + let swapchain_loader = Swapchain::new(&instance, &device).expect("Unable to load swapchain"); let swapchain_create_info = vk::SwapchainCreateInfoKHR { s_type: vk::StructureType::SwapchainCreateInfoKhr, p_next: ptr::null(), diff --git a/src/extensions/debug_report.rs b/src/extensions/debug_report.rs index 7bdefcc..32cc1ba 100644 --- a/src/extensions/debug_report.rs +++ b/src/extensions/debug_report.rs @@ -12,18 +12,17 @@ pub struct DebugReport { } impl DebugReport { - pub fn new(entry: &Entry, instance: &Instance) -> DebugReport { + pub fn new(entry: &Entry, instance: &Instance) -> Result { let debug_report_fn = vk::DebugReportFn::load(|name| { - unsafe { - mem::transmute(entry.static_fn - .get_instance_proc_addr(instance.handle, name.as_ptr())) - } - }) - .unwrap(); - DebugReport { + unsafe { + mem::transmute(entry.static_fn + .get_instance_proc_addr(instance.handle, name.as_ptr())) + } + })?; + Ok(DebugReport { handle: instance.handle, debug_report_fn: debug_report_fn, - } + }) } pub fn destroy_debug_report_callback_ext(&self, debug: vk::DebugReportCallbackEXT) { diff --git a/src/extensions/surface.rs b/src/extensions/surface.rs index b6000f8..006257d 100644 --- a/src/extensions/surface.rs +++ b/src/extensions/surface.rs @@ -11,18 +11,17 @@ pub struct Surface { } impl Surface { - pub fn new(entry: &Entry, instance: &Instance) -> Surface { + pub fn new(entry: &Entry, instance: &Instance) -> Result { let surface_fn = vk::SurfaceFn::load(|name| { - unsafe { - mem::transmute(entry.static_fn - .get_instance_proc_addr(instance.handle, name.as_ptr())) - } - }) - .unwrap(); - Surface { + unsafe { + mem::transmute(entry.static_fn + .get_instance_proc_addr(instance.handle, name.as_ptr())) + } + })?; + Ok(Surface { handle: instance.handle, surface_fn: surface_fn, - } + }) } pub fn get_physical_device_surface_support_khr(&self, @@ -111,4 +110,3 @@ impl Surface { } } } - diff --git a/src/extensions/swapchain.rs b/src/extensions/swapchain.rs index d25fb52..d157471 100644 --- a/src/extensions/swapchain.rs +++ b/src/extensions/swapchain.rs @@ -4,24 +4,24 @@ use std::mem; use instance::Instance; use device::Device; use vk; + pub struct Swapchain { handle: vk::Device, swapchain_fn: vk::SwapchainFn, } impl Swapchain { - pub fn new(instance: &Instance, device: &Device) -> Swapchain { + pub fn new(instance: &Instance, device: &Device) -> Result { let swapchain_fn = vk::SwapchainFn::load(|name| { - unsafe { - mem::transmute(instance.instance_fn - .get_device_proc_addr(device.handle, name.as_ptr())) - } - }) - .unwrap(); - Swapchain { + unsafe { + mem::transmute(instance.instance_fn + .get_device_proc_addr(device.handle, name.as_ptr())) + } + })?; + Ok(Swapchain { handle: device.handle, swapchain_fn: swapchain_fn, - } + }) } pub fn destroy_swapchain_khr(&self, swapchain: vk::SwapchainKHR) { diff --git a/src/extensions/xlibsurface.rs b/src/extensions/xlibsurface.rs index 38ab8dd..dadca44 100644 --- a/src/extensions/xlibsurface.rs +++ b/src/extensions/xlibsurface.rs @@ -11,21 +11,20 @@ pub struct XlibSurface { } impl XlibSurface { - pub fn new(entry: &Entry, instance: &Instance) -> XlibSurface { + pub fn new(entry: &Entry, instance: &Instance) -> Result { let surface_fn = vk::XlibSurfaceFn::load(|name| { - unsafe { - mem::transmute(entry.static_fn - .get_instance_proc_addr(instance.handle, name.as_ptr())) - } - }) - .unwrap(); - XlibSurface { + unsafe { + mem::transmute(entry.static_fn + .get_instance_proc_addr(instance.handle, name.as_ptr())) + } + })?; + Ok(XlibSurface { handle: instance.handle, xlib_surface_fn: surface_fn, - } + }) } - pub fn create_xlib_surface_khr(&self, + pub fn create_xlib_surface_khr(&self, create_info: &vk::XlibSurfaceCreateInfoKHR) -> VkResult { unsafe { diff --git a/src/instance.rs b/src/instance.rs index c3366f7..8a17b70 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -19,7 +19,6 @@ pub struct Instance { pub instance_fn: vk::InstanceFn, } - impl Instance { pub unsafe fn from_raw(handle: vk::Instance, instance_fn: vk::InstanceFn) -> Self { Instance {