Skip to content

Commit a48fcdc

Browse files
committed
Avoid dlsym unwrap. Add more possible library names.
1 parent 59f2701 commit a48fcdc

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/platform/with_egl/native_gl_context.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ use libloading as lib;
99

1010
lazy_static! {
1111
static ref GL_LIB: Option<lib::Library> = {
12-
if cfg!(target_os = "android") {
13-
lib::Library::new("libGLESv2.so").ok()
14-
} else {
15-
lib::Library::new("libGL.so").ok()
16-
}
12+
let names = ["libGLESv2.so", "libGL.so", "libGLESv3.so"];
13+
for name in &names {
14+
if let Ok(lib) = Library::new(name)
15+
return Some(lib)
16+
}
17+
}
18+
19+
None
1720
};
1821
}
1922
pub struct NativeGLContextHandle(pub EGLDisplay, pub EGLSurface);
@@ -88,8 +91,10 @@ impl NativeGLContextMethods for NativeGLContext {
8891
fn get_proc_address(addr: &str) -> *const () {
8992
unsafe {
9093
if let Some(ref lib) = *GL_LIB {
91-
let symbol: lib::Symbol<unsafe extern fn()> = lib.get(addr.as_bytes()).unwrap();
92-
return *symbol.deref() as *const();
94+
let symbol: Result<lib::Symbol<unsafe extern fn()>, _> = lib.get(addr.as_bytes());
95+
if let Ok(symbol) = symbol {
96+
return *symbol.deref() as *const ();
97+
}
9398
}
9499

95100
let addr = CString::new(addr.as_bytes());

0 commit comments

Comments
 (0)