mirror of
https://github.com/encounter/rust-sdl2.git
synced 2026-07-10 21:18:41 -07:00
Replace uses of deprecated mem::uninitialized with mem::MaybeUninit
This commit is contained in:
+19
-10
@@ -287,17 +287,18 @@ impl AudioSpecWAV {
|
||||
|
||||
/// Loads a WAVE from the data source.
|
||||
pub fn load_wav_rw(src: &mut RWops) -> Result<AudioSpecWAV, String> {
|
||||
use std::mem::uninitialized;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::ptr::null_mut;
|
||||
|
||||
let mut desired = unsafe { uninitialized::<sys::SDL_AudioSpec>() };
|
||||
let mut desired = MaybeUninit::uninit();
|
||||
let mut audio_buf: *mut u8 = null_mut();
|
||||
let mut audio_len: u32 = 0;
|
||||
unsafe {
|
||||
let ret = sys::SDL_LoadWAV_RW(src.raw(), 0, &mut desired, &mut audio_buf, &mut audio_len);
|
||||
let ret = sys::SDL_LoadWAV_RW(src.raw(), 0, desired.as_mut_ptr(), &mut audio_buf, &mut audio_len);
|
||||
if ret.is_null() {
|
||||
Err(get_error())
|
||||
} else {
|
||||
let desired = desired.assume_init();
|
||||
Ok(AudioSpecWAV {
|
||||
freq: desired.freq,
|
||||
format: AudioFormat::from_ll(desired.format).unwrap(),
|
||||
@@ -519,9 +520,11 @@ pub struct AudioQueue<Channel: AudioFormatNum> {
|
||||
impl<'a, Channel: AudioFormatNum> AudioQueue<Channel> {
|
||||
/// Opens a new audio device given the desired parameters and callback.
|
||||
pub fn open_queue<D: Into<Option<&'a str>>>(a: &AudioSubsystem, device: D, spec: &AudioSpecDesired) -> Result<AudioQueue<Channel>, String> {
|
||||
use std::mem::MaybeUninit;
|
||||
|
||||
let desired = AudioSpecDesired::convert_queue_to_ll::<Channel, Option<i32>, Option<u8>, Option<u16>>(spec.freq, spec.channels, spec.samples);
|
||||
|
||||
let mut obtained = unsafe { mem::uninitialized::<sys::SDL_AudioSpec>() };
|
||||
let mut obtained = MaybeUninit::uninit();
|
||||
unsafe {
|
||||
let device = match device.into() {
|
||||
Some(device) => Some(CString::new(device).unwrap()),
|
||||
@@ -532,13 +535,14 @@ impl<'a, Channel: AudioFormatNum> AudioQueue<Channel> {
|
||||
let iscapture_flag = 0;
|
||||
let device_id = sys::SDL_OpenAudioDevice(
|
||||
device_ptr as *const c_char, iscapture_flag, &desired,
|
||||
&mut obtained, 0
|
||||
obtained.as_mut_ptr(), 0
|
||||
);
|
||||
match device_id {
|
||||
0 => {
|
||||
Err(get_error())
|
||||
},
|
||||
id => {
|
||||
let obtained = obtained.assume_init();
|
||||
let device_id = AudioDeviceID::PlaybackDevice(id);
|
||||
let spec = AudioSpec::convert_from_ll(obtained);
|
||||
|
||||
@@ -608,11 +612,12 @@ impl<CB: AudioCallback> AudioDevice<CB> {
|
||||
F: FnOnce(AudioSpec) -> CB,
|
||||
D: Into<Option<&'a str>>,
|
||||
{
|
||||
use std::mem::MaybeUninit;
|
||||
|
||||
let mut userdata: Box<Option<CB>> = Box::new(None);
|
||||
let desired = AudioSpecDesired::convert_to_ll(spec.freq, spec.channels, spec.samples, &mut *userdata);
|
||||
|
||||
let mut obtained = unsafe { mem::uninitialized::<sys::SDL_AudioSpec>() };
|
||||
let mut obtained = MaybeUninit::uninit();
|
||||
unsafe {
|
||||
let device = match device.into() {
|
||||
Some(device) => Some(CString::new(device).unwrap()),
|
||||
@@ -623,13 +628,14 @@ impl<CB: AudioCallback> AudioDevice<CB> {
|
||||
let iscapture_flag = if capture { 1 } else { 0 };
|
||||
let device_id = sys::SDL_OpenAudioDevice(
|
||||
device_ptr as *const c_char, iscapture_flag, &desired,
|
||||
&mut obtained, 0
|
||||
obtained.as_mut_ptr(), 0
|
||||
);
|
||||
match device_id {
|
||||
0 => {
|
||||
Err(get_error())
|
||||
},
|
||||
id => {
|
||||
let obtained = obtained.assume_init();
|
||||
let device_id = AudioDeviceID::PlaybackDevice(id);
|
||||
let spec = AudioSpec::convert_from_ll(obtained);
|
||||
|
||||
@@ -741,13 +747,16 @@ impl AudioCVT {
|
||||
pub fn new(src_format: AudioFormat, src_channels: u8, src_rate: i32,
|
||||
dst_format: AudioFormat, dst_channels: u8, dst_rate: i32) -> Result<AudioCVT, String>
|
||||
{
|
||||
use std::mem;
|
||||
use std::mem::MaybeUninit;
|
||||
|
||||
let mut raw: MaybeUninit<sys::SDL_AudioCVT> = mem::MaybeUninit::uninit();
|
||||
|
||||
unsafe {
|
||||
let mut raw: sys::SDL_AudioCVT = mem::uninitialized();
|
||||
let ret = sys::SDL_BuildAudioCVT(&mut raw,
|
||||
let ret = sys::SDL_BuildAudioCVT(raw.as_mut_ptr(),
|
||||
src_format.to_ll(), src_channels, src_rate as c_int,
|
||||
dst_format.to_ll(), dst_channels, dst_rate as c_int);
|
||||
if ret == 1 || ret == 0 {
|
||||
let raw = raw.assume_init();
|
||||
Ok(AudioCVT { raw })
|
||||
} else {
|
||||
Err(get_error())
|
||||
|
||||
+54
-54
@@ -724,7 +724,7 @@ where S: Into<Option<Scancode>>,
|
||||
// but Event::User's raw pointers kind of removes that possibility.
|
||||
impl Event {
|
||||
fn to_ll(&self) -> Option<sys::SDL_Event> {
|
||||
let mut ret = unsafe { mem::uninitialized() };
|
||||
let mut ret = mem::MaybeUninit::uninit();
|
||||
match *self {
|
||||
Event::User { window_id, type_, code, data1, data2, timestamp} => {
|
||||
let event = sys::SDL_UserEvent {
|
||||
@@ -736,9 +736,9 @@ impl Event {
|
||||
data2
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_UserEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_UserEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
},
|
||||
|
||||
Event::Quit{timestamp} => {
|
||||
@@ -747,9 +747,9 @@ impl Event {
|
||||
timestamp,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_QuitEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_QuitEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
},
|
||||
|
||||
Event::Window{
|
||||
@@ -770,9 +770,9 @@ impl Event {
|
||||
data2,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_WindowEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_WindowEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
},
|
||||
|
||||
Event::KeyDown{
|
||||
@@ -795,9 +795,9 @@ impl Event {
|
||||
keysym,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_KeyboardEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_KeyboardEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
},
|
||||
Event::KeyUp {
|
||||
timestamp,
|
||||
@@ -819,9 +819,9 @@ impl Event {
|
||||
keysym,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_KeyboardEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_KeyboardEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
},
|
||||
Event::MouseMotion{
|
||||
timestamp,
|
||||
@@ -846,9 +846,9 @@ impl Event {
|
||||
yrel,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_MouseMotionEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_MouseMotionEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
|
||||
},
|
||||
Event::MouseButtonDown{
|
||||
@@ -873,9 +873,9 @@ impl Event {
|
||||
y
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_MouseButtonEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_MouseButtonEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
},
|
||||
Event::MouseButtonUp{
|
||||
timestamp,
|
||||
@@ -899,9 +899,9 @@ impl Event {
|
||||
y
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_MouseButtonEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_MouseButtonEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
},
|
||||
|
||||
Event::MouseWheel{
|
||||
@@ -922,9 +922,9 @@ impl Event {
|
||||
direction : direction.to_ll(),
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_MouseWheelEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_MouseWheelEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
},
|
||||
Event::JoyAxisMotion{
|
||||
timestamp,
|
||||
@@ -944,9 +944,9 @@ impl Event {
|
||||
padding4: 0
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_JoyAxisEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_JoyAxisEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
|
||||
},
|
||||
Event::JoyBallMotion{
|
||||
@@ -968,9 +968,9 @@ impl Event {
|
||||
padding3: 0
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_JoyBallEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_JoyBallEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
|
||||
},
|
||||
Event::JoyHatMotion{
|
||||
@@ -990,9 +990,9 @@ impl Event {
|
||||
padding2: 0
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_JoyHatEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_JoyHatEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
|
||||
},
|
||||
Event::JoyButtonDown{
|
||||
@@ -1010,9 +1010,9 @@ impl Event {
|
||||
padding2: 0,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_JoyButtonEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_JoyButtonEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
|
||||
},
|
||||
|
||||
@@ -1031,9 +1031,9 @@ impl Event {
|
||||
padding2: 0,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_JoyButtonEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_JoyButtonEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
|
||||
},
|
||||
|
||||
@@ -1047,9 +1047,9 @@ impl Event {
|
||||
which: which as i32,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_JoyDeviceEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_JoyDeviceEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
},
|
||||
|
||||
Event::JoyDeviceRemoved{
|
||||
@@ -1062,9 +1062,9 @@ impl Event {
|
||||
which,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_JoyDeviceEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_JoyDeviceEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
|
||||
},
|
||||
Event::ControllerAxisMotion{
|
||||
@@ -1086,9 +1086,9 @@ impl Event {
|
||||
padding4: 0,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_ControllerAxisEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_ControllerAxisEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
},
|
||||
Event::ControllerButtonDown{
|
||||
timestamp,
|
||||
@@ -1108,9 +1108,9 @@ impl Event {
|
||||
padding2: 0,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_ControllerButtonEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_ControllerButtonEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
},
|
||||
|
||||
Event::ControllerButtonUp{
|
||||
@@ -1129,9 +1129,9 @@ impl Event {
|
||||
padding2: 0,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_ControllerButtonEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_ControllerButtonEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
},
|
||||
|
||||
Event::ControllerDeviceAdded{
|
||||
@@ -1144,9 +1144,9 @@ impl Event {
|
||||
which: which as i32,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_ControllerDeviceEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_ControllerDeviceEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
|
||||
},
|
||||
|
||||
@@ -1160,9 +1160,9 @@ impl Event {
|
||||
which,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_ControllerDeviceEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_ControllerDeviceEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
|
||||
},
|
||||
|
||||
@@ -1176,9 +1176,9 @@ impl Event {
|
||||
which,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_ControllerDeviceEvent, 1);
|
||||
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_ControllerDeviceEvent, 1);
|
||||
Some(ret.assume_init())
|
||||
}
|
||||
Some(ret)
|
||||
|
||||
},
|
||||
|
||||
@@ -1637,26 +1637,26 @@ impl Event {
|
||||
}
|
||||
|
||||
unsafe fn poll_event() -> Option<Event> {
|
||||
let mut raw = mem::uninitialized();
|
||||
let has_pending = sys::SDL_PollEvent(&mut raw) == 1;
|
||||
let mut raw = mem::MaybeUninit::uninit();
|
||||
let has_pending = sys::SDL_PollEvent(raw.as_mut_ptr()) == 1;
|
||||
|
||||
if has_pending { Some(Event::from_ll(raw)) }
|
||||
if has_pending { Some(Event::from_ll(raw.assume_init())) }
|
||||
else { None }
|
||||
}
|
||||
|
||||
unsafe fn wait_event() -> Event {
|
||||
let mut raw = mem::uninitialized();
|
||||
let success = sys::SDL_WaitEvent(&mut raw) == 1;
|
||||
let mut raw = mem::MaybeUninit::uninit();
|
||||
let success = sys::SDL_WaitEvent(raw.as_mut_ptr()) == 1;
|
||||
|
||||
if success { Event::from_ll(raw) }
|
||||
if success { Event::from_ll(raw.assume_init()) }
|
||||
else { panic!(get_error()) }
|
||||
}
|
||||
|
||||
unsafe fn wait_event_timeout(timeout: u32) -> Option<Event> {
|
||||
let mut raw = mem::uninitialized();
|
||||
let success = sys::SDL_WaitEventTimeout(&mut raw, timeout as c_int) == 1;
|
||||
let mut raw = mem::MaybeUninit::uninit();
|
||||
let success = sys::SDL_WaitEventTimeout(raw.as_mut_ptr(), timeout as c_int) == 1;
|
||||
|
||||
if success { Some(Event::from_ll(raw)) }
|
||||
if success { Some(Event::from_ll(raw.assume_init())) }
|
||||
else { None }
|
||||
}
|
||||
|
||||
|
||||
+11
-10
@@ -452,9 +452,7 @@ impl Rect {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut out = unsafe {
|
||||
mem::uninitialized()
|
||||
};
|
||||
let mut out = mem::MaybeUninit::uninit();
|
||||
|
||||
let clip_ptr = match clipping_rect.as_ref() {
|
||||
Some(r) => r.raw(),
|
||||
@@ -466,11 +464,13 @@ impl Rect {
|
||||
Point::raw_slice(points),
|
||||
points.len() as i32,
|
||||
clip_ptr,
|
||||
&mut out
|
||||
out.as_mut_ptr()
|
||||
) != sys::SDL_bool::SDL_FALSE
|
||||
};
|
||||
|
||||
if result {
|
||||
let out = unsafe { out.assume_init() };
|
||||
|
||||
// Return an error if the dimensions are too large.
|
||||
Some(Rect::from_ll(out))
|
||||
} else {
|
||||
@@ -517,13 +517,14 @@ impl Rect {
|
||||
/// assert_eq!(rect.intersection(Rect::new(5, 0, 5, 5)), None);
|
||||
/// ```
|
||||
pub fn intersection(&self, other: Rect) -> Option<Rect> {
|
||||
let mut out = unsafe { mem::uninitialized() };
|
||||
let mut out = mem::MaybeUninit::uninit();
|
||||
|
||||
let success = unsafe {
|
||||
sys::SDL_IntersectRect(self.raw(), other.raw(), &mut out) != sys::SDL_bool::SDL_FALSE
|
||||
sys::SDL_IntersectRect(self.raw(), other.raw(), out.as_mut_ptr()) != sys::SDL_bool::SDL_FALSE
|
||||
};
|
||||
|
||||
if success {
|
||||
let out = unsafe { out.assume_init() };
|
||||
Some(Rect::from_ll(out))
|
||||
} else {
|
||||
None
|
||||
@@ -545,16 +546,16 @@ impl Rect {
|
||||
/// assert_eq!(rect.union(Rect::new(5, 0, 5, 5)), Rect::new(0, 0, 10, 5));
|
||||
/// ```
|
||||
pub fn union(&self, other: Rect) -> Rect {
|
||||
let mut out = unsafe {
|
||||
mem::uninitialized()
|
||||
};
|
||||
let mut out = mem::MaybeUninit::uninit();
|
||||
|
||||
unsafe {
|
||||
// If `self` and `other` are both empty, `out` remains uninitialized.
|
||||
// Because empty rectangles aren't allowed in Rect, we don't need to worry about this.
|
||||
sys::SDL_UnionRect(self.raw(), other.raw(), &mut out)
|
||||
sys::SDL_UnionRect(self.raw(), other.raw(), out.as_mut_ptr())
|
||||
};
|
||||
|
||||
let out = unsafe { out.assume_init() };
|
||||
|
||||
Rect::from_ll(out)
|
||||
}
|
||||
|
||||
|
||||
+28
-20
@@ -49,7 +49,7 @@ use std::ffi::CStr;
|
||||
use num::FromPrimitive;
|
||||
use std::vec::Vec;
|
||||
use crate::common::{validate_int, IntegerOrSdlError};
|
||||
use std::mem::{transmute, uninitialized};
|
||||
use std::mem::{transmute, MaybeUninit};
|
||||
use libc::c_void;
|
||||
|
||||
use crate::sys;
|
||||
@@ -209,12 +209,15 @@ impl<T> Drop for RendererContext<T> {
|
||||
impl<T> RendererContext<T> {
|
||||
/// Gets information about the rendering context.
|
||||
pub fn info(&self) -> RendererInfo {
|
||||
unsafe {
|
||||
let mut renderer_info_raw = mem::uninitialized();
|
||||
if sys::SDL_GetRendererInfo(self.raw, &mut renderer_info_raw) != 0 {
|
||||
// Should only fail on an invalid renderer
|
||||
panic!();
|
||||
} else {
|
||||
let mut renderer_info_raw = mem::MaybeUninit::uninit();
|
||||
let result = unsafe { sys::SDL_GetRendererInfo(self.raw, renderer_info_raw.as_mut_ptr()) != 0 };
|
||||
|
||||
if result {
|
||||
// Should only fail on an invalid renderer
|
||||
panic!();
|
||||
} else {
|
||||
unsafe {
|
||||
let renderer_info_raw = renderer_info_raw.assume_init();
|
||||
RendererInfo::from_ll(&renderer_info_raw)
|
||||
}
|
||||
}
|
||||
@@ -939,13 +942,14 @@ impl<T: RenderTarget> Canvas<T> {
|
||||
|
||||
/// Gets the blend mode used for drawing operations.
|
||||
pub fn blend_mode(&self) -> BlendMode {
|
||||
let mut blend: SDL_BlendMode;
|
||||
unsafe { blend = uninitialized(); }
|
||||
let ret = unsafe { sys::SDL_GetRenderDrawBlendMode(self.context.raw, &mut blend) };
|
||||
let mut blend: MaybeUninit<SDL_BlendMode> = mem::MaybeUninit::uninit();
|
||||
let ret = unsafe { sys::SDL_GetRenderDrawBlendMode(self.context.raw, blend.as_mut_ptr()) };
|
||||
// Should only fail on an invalid renderer
|
||||
if ret != 0 {
|
||||
panic!(get_error())
|
||||
} else {
|
||||
let blend = unsafe { blend.assume_init() };
|
||||
|
||||
FromPrimitive::from_i64(blend as i64).unwrap()
|
||||
}
|
||||
}
|
||||
@@ -1020,8 +1024,9 @@ impl<T: RenderTarget> Canvas<T> {
|
||||
|
||||
/// Gets the drawing area for the current target.
|
||||
pub fn viewport(&self) -> Rect {
|
||||
let mut rect = unsafe { mem::uninitialized() };
|
||||
unsafe { sys::SDL_RenderGetViewport(self.context.raw, &mut rect) };
|
||||
let mut rect = mem::MaybeUninit::uninit();
|
||||
unsafe { sys::SDL_RenderGetViewport(self.context.raw, rect.as_mut_ptr()) };
|
||||
let rect = unsafe { rect.assume_init() };
|
||||
Rect::from_ll(rect)
|
||||
}
|
||||
|
||||
@@ -1045,8 +1050,9 @@ impl<T: RenderTarget> Canvas<T> {
|
||||
///
|
||||
/// Returns `None` if clipping is disabled.
|
||||
pub fn clip_rect(&self) -> Option<Rect> {
|
||||
let mut raw = unsafe { mem::uninitialized() };
|
||||
unsafe { sys::SDL_RenderGetClipRect(self.context.raw, &mut raw) };
|
||||
let mut raw = mem::MaybeUninit::uninit();
|
||||
unsafe { sys::SDL_RenderGetClipRect(self.context.raw, raw.as_mut_ptr()) };
|
||||
let raw = unsafe { raw.assume_init() };
|
||||
if raw.w == 0 || raw.h == 0 {
|
||||
None
|
||||
} else {
|
||||
@@ -1739,14 +1745,14 @@ impl InternalTexture {
|
||||
}
|
||||
|
||||
pub fn blend_mode(&self) -> BlendMode {
|
||||
let mut blend: SDL_BlendMode;
|
||||
unsafe { blend = uninitialized(); }
|
||||
let ret = unsafe { sys::SDL_GetTextureBlendMode(self.raw, &mut blend) };
|
||||
let mut blend: MaybeUninit<SDL_BlendMode> = mem::MaybeUninit::uninit();
|
||||
let ret = unsafe { sys::SDL_GetTextureBlendMode(self.raw, blend.as_mut_ptr()) };
|
||||
|
||||
// Should only fail on an invalid texture
|
||||
if ret != 0 {
|
||||
panic!(get_error())
|
||||
} else {
|
||||
let blend = unsafe { blend.assume_init() };
|
||||
FromPrimitive::from_i64(blend as i64).unwrap()
|
||||
}
|
||||
}
|
||||
@@ -2266,12 +2272,14 @@ impl Iterator for DriverIterator {
|
||||
if self.index >= self.length {
|
||||
None
|
||||
} else {
|
||||
let mut out = unsafe { mem::uninitialized() };
|
||||
let result = unsafe { sys::SDL_GetRenderDriverInfo(self.index, &mut out) == 0 };
|
||||
let mut out = mem::MaybeUninit::uninit();
|
||||
let result = unsafe { sys::SDL_GetRenderDriverInfo(self.index, out.as_mut_ptr()) == 0 };
|
||||
assert!(result, 0);
|
||||
self.index += 1;
|
||||
|
||||
unsafe { Some(RendererInfo::from_ll(&out)) }
|
||||
unsafe {
|
||||
Some(RendererInfo::from_ll(&out.assume_init()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -520,10 +520,12 @@ impl SurfaceRef {
|
||||
///
|
||||
/// Returns `None` if clipping is disabled.
|
||||
pub fn clip_rect(&self) -> Option<Rect> {
|
||||
let mut raw = unsafe { mem::uninitialized() };
|
||||
let mut raw = mem::MaybeUninit::uninit();
|
||||
unsafe {
|
||||
sys::SDL_GetClipRect(self.raw(), &mut raw)
|
||||
sys::SDL_GetClipRect(self.raw(), raw.as_mut_ptr())
|
||||
};
|
||||
let raw = unsafe { raw.assume_init() };
|
||||
|
||||
if raw.w == 0 || raw.h == 0 {
|
||||
None
|
||||
} else {
|
||||
|
||||
+18
-12
@@ -620,10 +620,11 @@ impl VideoSubsystem {
|
||||
}
|
||||
|
||||
pub fn display_bounds(&self, display_index: i32) -> Result<Rect, String> {
|
||||
let mut out = unsafe { mem::uninitialized() };
|
||||
let result = unsafe { sys::SDL_GetDisplayBounds(display_index as c_int, &mut out) == 0 };
|
||||
let mut out = mem::MaybeUninit::uninit();
|
||||
let result = unsafe { sys::SDL_GetDisplayBounds(display_index as c_int, out.as_mut_ptr()) == 0 };
|
||||
|
||||
if result {
|
||||
let out = unsafe { out.assume_init() };
|
||||
Ok(Rect::from_ll(out))
|
||||
} else {
|
||||
Err(get_error())
|
||||
@@ -640,10 +641,11 @@ impl VideoSubsystem {
|
||||
}
|
||||
|
||||
pub fn display_mode(&self, display_index: i32, mode_index: i32) -> Result<DisplayMode, String> {
|
||||
let mut dm = unsafe { mem::uninitialized() };
|
||||
let result = unsafe { sys::SDL_GetDisplayMode(display_index as c_int, mode_index as c_int, &mut dm) == 0};
|
||||
let mut dm = mem::MaybeUninit::uninit();
|
||||
let result = unsafe { sys::SDL_GetDisplayMode(display_index as c_int, mode_index as c_int, dm.as_mut_ptr()) == 0};
|
||||
|
||||
if result {
|
||||
let dm = unsafe { dm.assume_init() };
|
||||
Ok(DisplayMode::from_ll(&dm))
|
||||
} else {
|
||||
Err(get_error())
|
||||
@@ -651,10 +653,11 @@ impl VideoSubsystem {
|
||||
}
|
||||
|
||||
pub fn desktop_display_mode(&self, display_index: i32) -> Result<DisplayMode, String> {
|
||||
let mut dm = unsafe { mem::uninitialized() };
|
||||
let result = unsafe { sys::SDL_GetDesktopDisplayMode(display_index as c_int, &mut dm) == 0};
|
||||
let mut dm = mem::MaybeUninit::uninit();
|
||||
let result = unsafe { sys::SDL_GetDesktopDisplayMode(display_index as c_int, dm.as_mut_ptr()) == 0};
|
||||
|
||||
if result {
|
||||
let dm = unsafe { dm.assume_init() };
|
||||
Ok(DisplayMode::from_ll(&dm))
|
||||
} else {
|
||||
Err(get_error())
|
||||
@@ -662,10 +665,11 @@ impl VideoSubsystem {
|
||||
}
|
||||
|
||||
pub fn current_display_mode(&self, display_index: i32) -> Result<DisplayMode, String> {
|
||||
let mut dm = unsafe { mem::uninitialized() };
|
||||
let result = unsafe { sys::SDL_GetCurrentDisplayMode(display_index as c_int, &mut dm) == 0};
|
||||
let mut dm = mem::MaybeUninit::uninit();
|
||||
let result = unsafe { sys::SDL_GetCurrentDisplayMode(display_index as c_int, dm.as_mut_ptr()) == 0};
|
||||
|
||||
if result {
|
||||
let dm = unsafe { dm.assume_init() };
|
||||
Ok(DisplayMode::from_ll(&dm))
|
||||
} else {
|
||||
Err(get_error())
|
||||
@@ -674,13 +678,14 @@ impl VideoSubsystem {
|
||||
|
||||
pub fn closest_display_mode(&self, display_index: i32, mode: &DisplayMode) -> Result<DisplayMode, String> {
|
||||
let input = mode.to_ll();
|
||||
let mut dm = unsafe { mem::uninitialized() };
|
||||
let mut dm = mem::MaybeUninit::uninit();
|
||||
|
||||
let result = unsafe { sys::SDL_GetClosestDisplayMode(display_index as c_int, &input, &mut dm) };
|
||||
let result = unsafe { sys::SDL_GetClosestDisplayMode(display_index as c_int, &input, dm.as_mut_ptr()) };
|
||||
|
||||
if result.is_null() {
|
||||
Err(get_error())
|
||||
} else {
|
||||
let dm = unsafe { dm.assume_init() };
|
||||
Ok(DisplayMode::from_ll(&dm))
|
||||
}
|
||||
}
|
||||
@@ -1183,16 +1188,17 @@ impl Window {
|
||||
}
|
||||
|
||||
pub fn display_mode(&self) -> Result<DisplayMode, String> {
|
||||
let mut dm = unsafe { mem::uninitialized() };
|
||||
let mut dm = mem::MaybeUninit::uninit();
|
||||
|
||||
let result = unsafe {
|
||||
sys::SDL_GetWindowDisplayMode(
|
||||
self.context.raw,
|
||||
&mut dm
|
||||
dm.as_mut_ptr(),
|
||||
) == 0
|
||||
};
|
||||
|
||||
if result {
|
||||
let dm = unsafe { dm.assume_init() };
|
||||
Ok(DisplayMode::from_ll(&dm))
|
||||
} else {
|
||||
Err(get_error())
|
||||
|
||||
Reference in New Issue
Block a user