aboutsummaryrefslogtreecommitdiffstats
path: root/src/win32
diff options
context:
space:
mode:
authorTomaka17 <pierre.krieger1708@gmail.com>2014-11-05 16:42:18 +0100
committerTomaka17 <pierre.krieger1708@gmail.com>2014-11-05 16:42:18 +0100
commit584bb3e7df751d55aad189eacd85b1cd6c5aa5c5 (patch)
tree91711433533faa6b44f62eb752d54c0a39129e12 /src/win32
parent7ce851dad9102c28ee2fd372ed9fd62e73364da9 (diff)
downloadglutin-584bb3e7df751d55aad189eacd85b1cd6c5aa5c5.tar.gz
glutin-584bb3e7df751d55aad189eacd85b1cd6c5aa5c5.zip
Use a proper error type for window creation
Diffstat (limited to 'src/win32')
-rw-r--r--src/win32/init.rs52
-rw-r--r--src/win32/mod.rs6
2 files changed, 29 insertions, 29 deletions
diff --git a/src/win32/init.rs b/src/win32/init.rs
index 73a6a6a..beef44b 100644
--- a/src/win32/init.rs
+++ b/src/win32/init.rs
@@ -6,7 +6,7 @@ use std::sync::atomic::AtomicBool;
use std::ptr;
use super::{event, ffi};
use super::Window;
-use Event;
+use {CreationError, OsError, Event};
/// Stores the current window and its events dispatcher.
///
@@ -17,7 +17,7 @@ local_data_key!(WINDOW: (ffi::HWND, Sender<Event>))
pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: String,
builder_monitor: Option<super::MonitorID>,
builder_gl_version: Option<(uint, uint)>, builder_vsync: bool,
- builder_hidden: bool) -> Result<Window, String>
+ builder_hidden: bool) -> Result<Window, CreationError>
{
use std::mem;
use std::os;
@@ -94,7 +94,7 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin
&mut screen_settings, ptr::null(), ffi::CDS_FULLSCREEN, ptr::null_mut()) };
if result != ffi::DISP_CHANGE_SUCCESSFUL {
- tx.send(Err(format!("ChangeDisplaySettings failed: {}", result)));
+ tx.send(Err(OsError(format!("ChangeDisplaySettings failed: {}", result))));
return;
}
}
@@ -125,8 +125,8 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin
if handle.is_null() {
use std::os;
- tx.send(Err(format!("CreateWindowEx function failed: {}",
- os::error_string(os::errno() as uint))));
+ tx.send(Err(OsError(format!("CreateWindowEx function failed: {}",
+ os::error_string(os::errno() as uint)))));
return;
}
@@ -137,8 +137,8 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin
let dummy_hdc = {
let hdc = unsafe { ffi::GetDC(dummy_window) };
if hdc.is_null() {
- tx.send(Err(format!("GetDC function failed: {}",
- os::error_string(os::errno() as uint))));
+ tx.send(Err(OsError(format!("GetDC function failed: {}",
+ os::error_string(os::errno() as uint)))));
unsafe { ffi::DestroyWindow(dummy_window); }
return;
}
@@ -165,8 +165,8 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin
let pf_index = unsafe { ffi::ChoosePixelFormat(dummy_hdc, &output) };
if pf_index == 0 {
- tx.send(Err(format!("ChoosePixelFormat function failed: {}",
- os::error_string(os::errno() as uint))));
+ tx.send(Err(OsError(format!("ChoosePixelFormat function failed: {}",
+ os::error_string(os::errno() as uint)))));
unsafe { ffi::DestroyWindow(dummy_window); }
return;
}
@@ -174,8 +174,8 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin
if unsafe { ffi::DescribePixelFormat(dummy_hdc, pf_index,
mem::size_of::<ffi::PIXELFORMATDESCRIPTOR>() as ffi::UINT, &mut output) } == 0
{
- tx.send(Err(format!("DescribePixelFormat function failed: {}",
- os::error_string(os::errno() as uint))));
+ tx.send(Err(OsError(format!("DescribePixelFormat function failed: {}",
+ os::error_string(os::errno() as uint)))));
unsafe { ffi::DestroyWindow(dummy_window); }
return;
}
@@ -186,8 +186,8 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin
// calling SetPixelFormat
unsafe {
if ffi::SetPixelFormat(dummy_hdc, 1, &pixel_format) == 0 {
- tx.send(Err(format!("SetPixelFormat function failed: {}",
- os::error_string(os::errno() as uint))));
+ tx.send(Err(OsError(format!("SetPixelFormat function failed: {}",
+ os::error_string(os::errno() as uint)))));
ffi::DestroyWindow(dummy_window);
return;
}
@@ -197,8 +197,8 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin
let dummy_context = {
let ctxt = unsafe { ffi::wgl::CreateContext(dummy_hdc) };
if ctxt.is_null() {
- tx.send(Err(format!("wglCreateContext function failed: {}",
- os::error_string(os::errno() as uint))));
+ tx.send(Err(OsError(format!("wglCreateContext function failed: {}",
+ os::error_string(os::errno() as uint)))));
unsafe { ffi::DestroyWindow(dummy_window); }
return;
}
@@ -254,8 +254,8 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin
if handle.is_null() {
use std::os;
- tx.send(Err(format!("CreateWindowEx function failed: {}",
- os::error_string(os::errno() as uint))));
+ tx.send(Err(OsError(format!("CreateWindowEx function failed: {}",
+ os::error_string(os::errno() as uint)))));
return;
}
@@ -266,8 +266,8 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin
let hdc = {
let hdc = unsafe { ffi::GetDC(real_window) };
if hdc.is_null() {
- tx.send(Err(format!("GetDC function failed: {}",
- os::error_string(os::errno() as uint))));
+ tx.send(Err(OsError(format!("GetDC function failed: {}",
+ os::error_string(os::errno() as uint)))));
unsafe { ffi::DestroyWindow(real_window); }
return;
}
@@ -277,8 +277,8 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin
// calling SetPixelFormat
unsafe {
if ffi::SetPixelFormat(hdc, 1, &pixel_format) == 0 {
- tx.send(Err(format!("SetPixelFormat function failed: {}",
- os::error_string(os::errno() as uint))));
+ tx.send(Err(OsError(format!("SetPixelFormat function failed: {}",
+ os::error_string(os::errno() as uint)))));
ffi::DestroyWindow(real_window);
return;
}
@@ -310,8 +310,8 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin
};
if ctxt.is_null() {
- tx.send(Err(format!("OpenGL context creation failed: {}",
- os::error_string(os::errno() as uint))));
+ tx.send(Err(OsError(format!("OpenGL context creation failed: {}",
+ os::error_string(os::errno() as uint)))));
unsafe { ffi::DestroyWindow(real_window); }
return;
}
@@ -337,8 +337,8 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin
.collect::<Vec<u16>>().as_ptr();
let lib = unsafe { ffi::LoadLibraryW(name) };
if lib.is_null() {
- tx.send(Err(format!("LoadLibrary function failed: {}",
- os::error_string(os::errno() as uint))));
+ tx.send(Err(OsError(format!("LoadLibrary function failed: {}",
+ os::error_string(os::errno() as uint)))));
unsafe { ffi::wgl::DeleteContext(context); }
unsafe { ffi::DestroyWindow(real_window); }
return;
@@ -351,7 +351,7 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin
if extra_functions.SwapIntervalEXT.is_loaded() {
unsafe { ffi::wgl::MakeCurrent(hdc, context) };
if unsafe { extra_functions.SwapIntervalEXT(1) } == 0 {
- tx.send(Err(format!("wglSwapIntervalEXT failed")));
+ tx.send(Err(OsError(format!("wglSwapIntervalEXT failed"))));
unsafe { ffi::wgl::DeleteContext(context); }
unsafe { ffi::DestroyWindow(real_window); }
return;
diff --git a/src/win32/mod.rs b/src/win32/mod.rs
index facfb6d..282b0bb 100644
--- a/src/win32/mod.rs
+++ b/src/win32/mod.rs
@@ -1,7 +1,7 @@
use std::sync::atomic::AtomicBool;
use std::ptr;
use libc;
-use Event;
+use {CreationError, Event};
#[cfg(feature = "window")]
use WindowBuilder;
@@ -23,7 +23,7 @@ pub struct HeadlessContext(Window);
#[cfg(feature = "headless")]
impl HeadlessContext {
/// See the docs in the crate root file.
- pub fn new(builder: HeadlessRendererBuilder) -> Result<HeadlessContext, String> {
+ pub fn new(builder: HeadlessRendererBuilder) -> Result<HeadlessContext, CreationError> {
let HeadlessRendererBuilder { dimensions, gl_version } = builder;
init::new_window(Some(dimensions), "".to_string(), None, gl_version, false, true)
.map(|w| HeadlessContext(w))
@@ -67,7 +67,7 @@ pub struct Window {
#[cfg(feature = "window")]
impl Window {
/// See the docs in the crate root file.
- pub fn new(builder: WindowBuilder) -> Result<Window, String> {
+ pub fn new(builder: WindowBuilder) -> Result<Window, CreationError> {
let WindowBuilder { dimensions, title, monitor, gl_version, vsync, visible } = builder;
init::new_window(dimensions, title, monitor, gl_version, vsync, !visible)
}