Skip to content

Commit 8ee2600

Browse files
authored
egl/display: Pass *pointer to* output variable when querying DEVICE_EXT
By casting a `null_mut()` ptr and passing it directly _by value_ to `QueryDisplayAttribEXT()`, the function ignores writing the output as it didn't receive an address (it received `NULL`) to write the device to. Instead we should take the _pointer address of this `null_mut()` pointer_ and provide that to the function instead so that it can _overwrite_ it with a pointer to the requested `eglDevice`. This is even more clear when allocating a `MaybeUninit` in which the pointer will be returned, which has a convenient `.as_mut_ptr()` member to pass its pointer value directly into `QueryDisplayAttribEXT()`.
1 parent 7ec3bb9 commit 8ee2600

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Fixed EGL's `Device::query_devices()` being too strict about required extensions
44
- Fixed crash in `EglGetProcAddress` on Win32-x86 platform due to wrong calling convention
5+
- Fixed EGL's `Display::device()` always returning an error due to invalid pointer-argument passing inside
56

67
# Version 0.32.0
78

glutin/src/api/egl/display.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
33
use std::collections::HashSet;
44
use std::ffi::{self, CStr};
5+
use std::fmt;
56
use std::mem::MaybeUninit;
67
use std::ops::Deref;
78
use std::os::raw::c_char;
89
use std::sync::Arc;
9-
use std::{fmt, ptr};
1010

1111
use glutin_egl_sys::egl;
1212
use glutin_egl_sys::egl::types::{EGLAttrib, EGLDisplay, EGLint};
@@ -193,12 +193,12 @@ impl Display {
193193
.into());
194194
}
195195

196-
let device = ptr::null_mut();
196+
let mut device = MaybeUninit::uninit();
197197
if unsafe {
198198
self.inner.egl.QueryDisplayAttribEXT(
199199
*self.inner.raw,
200200
egl::DEVICE_EXT as EGLint,
201-
device as *mut _,
201+
device.as_mut_ptr(),
202202
)
203203
} == egl::FALSE
204204
{
@@ -211,6 +211,13 @@ impl Display {
211211
}));
212212
}
213213

214+
let device = unsafe { device.assume_init() } as egl::types::EGLDeviceEXT;
215+
debug_assert_ne!(
216+
device,
217+
egl::NO_DEVICE_EXT,
218+
"eglQueryDisplayAttribEXT(EGL_DEVICE_EXT) should never return EGL_NO_DEVICE_EXT on \
219+
success"
220+
);
214221
Device::from_ptr(self.inner.egl, device)
215222
}
216223

0 commit comments

Comments
 (0)