aboutsummaryrefslogtreecommitdiffstats
path: root/src/win32
diff options
context:
space:
mode:
authorTomaka17 <pierre.krieger1708@gmail.com>2014-08-01 23:12:46 +0200
committerTomaka17 <pierre.krieger1708@gmail.com>2014-08-01 23:12:46 +0200
commitc1ecc06bafb81166c36e5ea113b0b8edbb73272c (patch)
tree46cfd6ddcd55dfb5743d79823944e919130e0281 /src/win32
parentd93cea808d73adba3de3611f172134bd9e3b0afe (diff)
downloadglutin-c1ecc06bafb81166c36e5ea113b0b8edbb73272c.tar.gz
glutin-c1ecc06bafb81166c36e5ea113b0b8edbb73272c.zip
Change the RegisterClass code.
Prevents an issue when creating multiple contexts.
Diffstat (limited to 'src/win32')
-rw-r--r--src/win32/init.rs49
1 files changed, 26 insertions, 23 deletions
diff --git a/src/win32/init.rs b/src/win32/init.rs
index 8987d2e..81fc647 100644
--- a/src/win32/init.rs
+++ b/src/win32/init.rs
@@ -31,31 +31,34 @@ pub fn new_window(dimensions: Option<(uint, uint)>, title: &str,
// This is the only safe method. Using `nosend` wouldn't work for non-native runtime.
TaskBuilder::new().native().spawn(proc() {
// registering the window class
- let class_name: Vec<u16> = "Window Class".utf16_units().collect::<Vec<u16>>()
- .append_one(0);
-
- let class = ffi::WNDCLASSEX {
- cbSize: mem::size_of::<ffi::WNDCLASSEX>() as ffi::UINT,
- style: ffi::CS_HREDRAW | ffi::CS_VREDRAW,
- lpfnWndProc: callback,
- cbClsExtra: 0,
- cbWndExtra: 0,
- hInstance: unsafe { ffi::GetModuleHandleW(ptr::null()) },
- hIcon: ptr::mut_null(),
- hCursor: ptr::mut_null(),
- hbrBackground: ptr::mut_null(),
- lpszMenuName: ptr::null(),
- lpszClassName: class_name.as_ptr(),
- hIconSm: ptr::mut_null(),
+ let class_name = {
+ let class_name: Vec<u16> = "Window Class".utf16_units().collect::<Vec<u16>>()
+ .append_one(0);
+
+ let class = ffi::WNDCLASSEX {
+ cbSize: mem::size_of::<ffi::WNDCLASSEX>() as ffi::UINT,
+ style: ffi::CS_HREDRAW | ffi::CS_VREDRAW,
+ lpfnWndProc: callback,
+ cbClsExtra: 0,
+ cbWndExtra: 0,
+ hInstance: unsafe { ffi::GetModuleHandleW(ptr::null()) },
+ hIcon: ptr::mut_null(),
+ hCursor: ptr::mut_null(),
+ hbrBackground: ptr::mut_null(),
+ lpszMenuName: ptr::null(),
+ lpszClassName: class_name.as_ptr(),
+ hIconSm: ptr::mut_null(),
+ };
+
+ // We ignore errors because registering the same window class twice would trigger
+ // an error, and because errors here are detected during CreateWindowEx anyway.
+ // Also since there is no weird element in the struct, there is no reason for this
+ // call to fail.
+ unsafe { ffi::RegisterClassExW(&class) };
+
+ class_name
};
- if unsafe { ffi::RegisterClassExW(&class) } == 0 {
- use std::os;
- tx.send(Err(format!("RegisterClassEx function failed: {}",
- os::error_string(os::errno() as uint))));
- return;
- }
-
// building a RECT object with coordinates
let mut rect = ffi::RECT {
left: 0, right: dimensions.map(|(w, _)| w as ffi::LONG).unwrap_or(1024),