Fix result access

This commit is contained in:
hodasemi 2023-12-04 13:59:05 +01:00
parent 9130e0d8df
commit c54b4c1c24
2 changed files with 9 additions and 5 deletions

View file

@ -1,5 +1,5 @@
use crate::prelude::*; use crate::prelude::*;
use crate::structs::raw_to_slice; use crate::structs::{raw_to_slice, raw_to_slice_mut};
use std::os::raw::c_void; use std::os::raw::c_void;
use std::ptr; use std::ptr;
@ -74,11 +74,11 @@ impl VkPresentInfoKHR {
swapchain_infos swapchain_infos
} }
pub fn results(&self) -> &[VkResult] { pub fn results(&mut self) -> &mut [VkResult] {
if self.waitSemaphoreCount == 0 || self.pResults != ptr::null_mut() { if self.swapchainCount == 0 || self.pResults != ptr::null_mut() {
&[] &mut []
} else { } else {
raw_to_slice(self.pResults, self.waitSemaphoreCount) raw_to_slice_mut(self.pResults, self.swapchainCount)
} }
} }
} }

View file

@ -21,3 +21,7 @@ use std::slice;
fn raw_to_slice<'a, T: Clone>(pointer: *const T, size: u32) -> &'a [T] { fn raw_to_slice<'a, T: Clone>(pointer: *const T, size: u32) -> &'a [T] {
unsafe { slice::from_raw_parts(pointer, size as usize) } unsafe { slice::from_raw_parts(pointer, size as usize) }
} }
fn raw_to_slice_mut<'a, T: Clone>(pointer: *mut T, size: u32) -> &'a mut [T] {
unsafe { slice::from_raw_parts_mut(pointer, size as usize) }
}