From 1a33c9ce9fa5f932d71e2eadf5b7f4ac29b187ee Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Mon, 16 Feb 2015 15:57:17 +0100 Subject: [PATCH] Extract load_opengl32_dll --- src/win32/init.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/win32/init.rs b/src/win32/init.rs index 9803e432..90a6035b 100644 --- a/src/win32/init.rs +++ b/src/win32/init.rs @@ -258,19 +258,7 @@ fn init(title: Vec, builder: BuilderAttribs<'static>, builder_sharelists: O }; // loading the opengl32 module - let gl_library = { - let name = "opengl32.dll".utf16_units().chain(Some(0).into_iter()) - .collect::>().as_ptr(); - let lib = unsafe { kernel32::LoadLibraryW(name) }; - if lib.is_null() { - let err = Err(OsError(format!("LoadLibrary function failed: {}", - os::error_string(os::errno() as usize)))); - unsafe { gl::wgl::DeleteContext(context as *const libc::c_void); } - unsafe { user32::DestroyWindow(real_window); } - return err; - } - lib - }; + let gl_library = try!(load_opengl32_dll()); // handling vsync if builder.vsync { @@ -511,3 +499,17 @@ fn enumerate_arb_pixel_formats(extra: &gl::wgl_extra::Wgl, hdc: winapi::HDC) result } + +fn load_opengl32_dll() -> Result { + let name = "opengl32.dll".utf16_units().chain(Some(0).into_iter()) + .collect::>().as_ptr(); + + let lib = unsafe { kernel32::LoadLibraryW(name) }; + + if lib.is_null() { + return Err(OsError(format!("LoadLibrary function failed: {}", + os::error_string(os::errno() as usize)))); + } + + Ok(lib) +}