Skip to content

Commit d6fec79

Browse files
committed
Cleanup temporary objects in case of error during creation on win32
See #10
1 parent 5c92587 commit d6fec79

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/win32/init.rs

+10
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {
135135
if hdc.is_null() {
136136
tx.send(Err(format!("GetDC function failed: {}",
137137
os::error_string(os::errno() as uint))));
138+
unsafe { ffi::DestroyWindow(dummy_window); }
138139
return;
139140
}
140141
hdc
@@ -162,6 +163,7 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {
162163
if pf_index == 0 {
163164
tx.send(Err(format!("ChoosePixelFormat function failed: {}",
164165
os::error_string(os::errno() as uint))));
166+
unsafe { ffi::DestroyWindow(dummy_window); }
165167
return;
166168
}
167169

@@ -170,6 +172,7 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {
170172
{
171173
tx.send(Err(format!("DescribePixelFormat function failed: {}",
172174
os::error_string(os::errno() as uint))));
175+
unsafe { ffi::DestroyWindow(dummy_window); }
173176
return;
174177
}
175178

@@ -181,6 +184,7 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {
181184
if ffi::SetPixelFormat(dummy_hdc, 1, &pixel_format) == 0 {
182185
tx.send(Err(format!("SetPixelFormat function failed: {}",
183186
os::error_string(os::errno() as uint))));
187+
ffi::DestroyWindow(dummy_window);
184188
return;
185189
}
186190
}
@@ -191,6 +195,7 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {
191195
if ctxt.is_null() {
192196
tx.send(Err(format!("wglCreateContext function failed: {}",
193197
os::error_string(os::errno() as uint))));
198+
unsafe { ffi::DestroyWindow(dummy_window); }
194199
return;
195200
}
196201
ctxt
@@ -259,6 +264,7 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {
259264
if hdc.is_null() {
260265
tx.send(Err(format!("GetDC function failed: {}",
261266
os::error_string(os::errno() as uint))));
267+
unsafe { ffi::DestroyWindow(real_window); }
262268
return;
263269
}
264270
hdc
@@ -269,6 +275,7 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {
269275
if ffi::SetPixelFormat(hdc, 1, &pixel_format) == 0 {
270276
tx.send(Err(format!("SetPixelFormat function failed: {}",
271277
os::error_string(os::errno() as uint))));
278+
ffi::DestroyWindow(real_window);
272279
return;
273280
}
274281
}
@@ -299,6 +306,7 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {
299306
if ctxt.is_null() {
300307
tx.send(Err(format!("OpenGL context creation failed: {}",
301308
os::error_string(os::errno() as uint))));
309+
unsafe { ffi::DestroyWindow(real_window); }
302310
return;
303311
}
304312

@@ -324,6 +332,8 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {
324332
if lib.is_null() {
325333
tx.send(Err(format!("LoadLibrary function failed: {}",
326334
os::error_string(os::errno() as uint))));
335+
unsafe { ffi::wglDeleteContext(context); }
336+
unsafe { ffi::DestroyWindow(real_window); }
327337
return;
328338
}
329339
lib

0 commit comments

Comments
 (0)