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) +}