mirror of
https://github.com/italicsjenga/rust_minifb.git
synced 2025-01-27 02:56:33 +11:00
Added more error checking when creating window
This commit is contained in:
parent
d8c2a38f39
commit
58565b9812
1 changed files with 13 additions and 9 deletions
|
@ -201,7 +201,7 @@ pub struct Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
fn open_window(name: &str, width: usize, height: usize, _: Scale, _: Vsync) -> HWND {
|
fn open_window(name: &str, width: usize, height: usize, _: Scale, _: Vsync) -> Option<HWND> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let class_name = to_wstring("minifb_window");
|
let class_name = to_wstring("minifb_window");
|
||||||
let s = CString::new(name).unwrap();
|
let s = CString::new(name).unwrap();
|
||||||
|
@ -219,7 +219,10 @@ impl Window {
|
||||||
lpszClassName: class_name,
|
lpszClassName: class_name,
|
||||||
};
|
};
|
||||||
|
|
||||||
user32::RegisterClassW(&class);
|
if user32::RegisterClassW(&class) == 0 {
|
||||||
|
println!("Unable to register class, error {}", kernel32::GetLastError() as u32);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
let mut rect = winapi::RECT {
|
let mut rect = winapi::RECT {
|
||||||
left: 0,
|
left: 0,
|
||||||
|
@ -249,13 +252,14 @@ impl Window {
|
||||||
ptr::null_mut(),
|
ptr::null_mut(),
|
||||||
ptr::null_mut(),
|
ptr::null_mut(),
|
||||||
ptr::null_mut());
|
ptr::null_mut());
|
||||||
|
if handle.is_null() {
|
||||||
if !handle.is_null() {
|
println!("Unable to register create window, error {}", kernel32::GetLastError() as u32);
|
||||||
user32::ShowWindow(handle, winapi::SW_NORMAL);
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user32::ShowWindow(handle, winapi::SW_NORMAL);
|
||||||
|
|
||||||
return handle;
|
return Some(handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,13 +272,13 @@ impl Window {
|
||||||
unsafe {
|
unsafe {
|
||||||
let handle = Self::open_window(name, width, height, scale, vsync);
|
let handle = Self::open_window(name, width, height, scale, vsync);
|
||||||
|
|
||||||
if handle.is_null() {
|
if handle.is_none() {
|
||||||
return Err("Unable to create Window");
|
return Err("Unable to create Window");
|
||||||
}
|
}
|
||||||
|
|
||||||
let window = Window {
|
let window = Window {
|
||||||
dc: Some(user32::GetDC(handle)),
|
dc: Some(user32::GetDC(handle.unwrap())),
|
||||||
window: Some(handle),
|
window: Some(handle.unwrap()),
|
||||||
keys: [false; 512],
|
keys: [false; 512],
|
||||||
buffer: Vec::new(),
|
buffer: Vec::new(),
|
||||||
is_open: true,
|
is_open: true,
|
||||||
|
|
Loading…
Add table
Reference in a new issue