Skip to content

Commit

Permalink
Avoid dlsym unwrap. Add more possible library names.
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed Mar 31, 2017
1 parent 59f2701 commit 06e074e
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/platform/with_egl/native_gl_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ use libloading as lib;

lazy_static! {
static ref GL_LIB: Option<lib::Library> = {
if cfg!(target_os = "android") {
lib::Library::new("libGLESv2.so").ok()
} else {
lib::Library::new("libGL.so").ok()
}
let names = ["libGLESv2.so", "libGLES.so", "libGLESv3.so"];
for name in &names {
let lib = lib::Library::new(name);
if lib.is_ok() {
return lib.ok();
}
}

None
};
}
pub struct NativeGLContextHandle(pub EGLDisplay, pub EGLSurface);
Expand Down Expand Up @@ -88,8 +92,10 @@ impl NativeGLContextMethods for NativeGLContext {
fn get_proc_address(addr: &str) -> *const () {
unsafe {
if let Some(ref lib) = *GL_LIB {
let symbol: lib::Symbol<unsafe extern fn()> = lib.get(addr.as_bytes()).unwrap();
return *symbol.deref() as *const();
let symbol: Result<lib::Symbol<unsafe extern fn()>, _> = lib.get(addr.as_bytes());
if let Ok(symbol) = symbol {
return *symbol.deref() as *const ();
}
}

let addr = CString::new(addr.as_bytes());
Expand Down

0 comments on commit 06e074e

Please sign in to comment.