Skip to content

Commit

Permalink
egl/display: Pass *pointer to* output variable when querying `DEVICE_…
Browse files Browse the repository at this point in the history
…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()`.
  • Loading branch information
MarijnS95 committed Sep 5, 2024
1 parent 7ec3bb9 commit 8ee2600
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

# Version 0.32.0

Expand Down
13 changes: 10 additions & 3 deletions glutin/src/api/egl/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

use std::collections::HashSet;
use std::ffi::{self, CStr};
use std::fmt;
use std::mem::MaybeUninit;
use std::ops::Deref;
use std::os::raw::c_char;
use std::sync::Arc;
use std::{fmt, ptr};

use glutin_egl_sys::egl;
use glutin_egl_sys::egl::types::{EGLAttrib, EGLDisplay, EGLint};
Expand Down Expand Up @@ -193,12 +193,12 @@ impl Display {
.into());
}

let device = ptr::null_mut();
let mut device = MaybeUninit::uninit();
if unsafe {
self.inner.egl.QueryDisplayAttribEXT(
*self.inner.raw,
egl::DEVICE_EXT as EGLint,
device as *mut _,
device.as_mut_ptr(),
)
} == egl::FALSE
{
Expand All @@ -211,6 +211,13 @@ impl Display {
}));
}

let device = unsafe { device.assume_init() } as egl::types::EGLDeviceEXT;
debug_assert_ne!(
device,
egl::NO_DEVICE_EXT,
"eglQueryDisplayAttribEXT(EGL_DEVICE_EXT) should never return EGL_NO_DEVICE_EXT on \
success"
);
Device::from_ptr(self.inner.egl, device)
}

Expand Down

0 comments on commit 8ee2600

Please sign in to comment.