aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomaka17 <pierre.krieger1708@gmail.com>2014-08-22 11:26:00 +0200
committerTomaka17 <pierre.krieger1708@gmail.com>2014-08-22 11:26:00 +0200
commitd6fec79334e5daf9d442b50860d786a28cf46b3d (patch)
tree8363b7f0fc4321563338f543818af3008ca63545
parent5c925874421c016d7c975491494035f78b14566a (diff)
downloadglutin-d6fec79334e5daf9d442b50860d786a28cf46b3d.tar.gz
glutin-d6fec79334e5daf9d442b50860d786a28cf46b3d.zip
Cleanup temporary objects in case of error during creation on win32
See #10
-rw-r--r--src/win32/init.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/win32/init.rs b/src/win32/init.rs
index 21d9612..9b6ec81 100644
--- a/src/win32/init.rs
+++ b/src/win32/init.rs
@@ -135,6 +135,7 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {
if hdc.is_null() {
tx.send(Err(format!("GetDC function failed: {}",
os::error_string(os::errno() as uint))));
+ unsafe { ffi::DestroyWindow(dummy_window); }
return;
}
hdc
@@ -162,6 +163,7 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {
if pf_index == 0 {
tx.send(Err(format!("ChoosePixelFormat function failed: {}",
os::error_string(os::errno() as uint))));
+ unsafe { ffi::DestroyWindow(dummy_window); }
return;
}
@@ -170,6 +172,7 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {
{
tx.send(Err(format!("DescribePixelFormat function failed: {}",
os::error_string(os::errno() as uint))));
+ unsafe { ffi::DestroyWindow(dummy_window); }
return;
}
@@ -181,6 +184,7 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {
if ffi::SetPixelFormat(dummy_hdc, 1, &pixel_format) == 0 {
tx.send(Err(format!("SetPixelFormat function failed: {}",
os::error_string(os::errno() as uint))));
+ ffi::DestroyWindow(dummy_window);
return;
}
}
@@ -191,6 +195,7 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {
if ctxt.is_null() {
tx.send(Err(format!("wglCreateContext function failed: {}",
os::error_string(os::errno() as uint))));
+ unsafe { ffi::DestroyWindow(dummy_window); }
return;
}
ctxt
@@ -259,6 +264,7 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {
if hdc.is_null() {
tx.send(Err(format!("GetDC function failed: {}",
os::error_string(os::errno() as uint))));
+ unsafe { ffi::DestroyWindow(real_window); }
return;
}
hdc
@@ -269,6 +275,7 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {
if ffi::SetPixelFormat(hdc, 1, &pixel_format) == 0 {
tx.send(Err(format!("SetPixelFormat function failed: {}",
os::error_string(os::errno() as uint))));
+ ffi::DestroyWindow(real_window);
return;
}
}
@@ -299,6 +306,7 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {
if ctxt.is_null() {
tx.send(Err(format!("OpenGL context creation failed: {}",
os::error_string(os::errno() as uint))));
+ unsafe { ffi::DestroyWindow(real_window); }
return;
}
@@ -324,6 +332,8 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {
if lib.is_null() {
tx.send(Err(format!("LoadLibrary function failed: {}",
os::error_string(os::errno() as uint))));
+ unsafe { ffi::wglDeleteContext(context); }
+ unsafe { ffi::DestroyWindow(real_window); }
return;
}
lib