Skip to content

Commit

Permalink
Merge #226
Browse files Browse the repository at this point in the history
226: check `gl.GetString` return value is `null` in `get_parameter_string` r=grovesNL a=zirconium-n

This fixes segfault (with an panic) under GL context 1.4, which is the default version of GL in WSL2.

Co-authored-by: Ziru Niu <niuzr@sudoprivacy.com>
  • Loading branch information
bors[bot] and Ziru Niu committed Sep 20, 2022
2 parents 3ef30bb + 498b072 commit 757fe99
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,12 @@ impl HasContext for Context {
unsafe fn get_parameter_string(&self, parameter: u32) -> String {
let gl = &self.raw;
let raw_ptr = gl.GetString(parameter);
if raw_ptr.is_null() {
panic!(
"Get parameter string 0x{:X} failed. Maybe your GL context version is too outdated.",
parameter
)
}
std::ffi::CStr::from_ptr(raw_ptr as *const native_gl::GLchar)
.to_str()
.unwrap()
Expand Down

0 comments on commit 757fe99

Please sign in to comment.