From 8ee26006f54be3521e569a8f05b90180024f4b74 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Thu, 5 Sep 2024 13:41:17 +0200 Subject: [PATCH] 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()`. --- CHANGELOG.md | 1 + glutin/src/api/egl/display.rs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f43ae9fe5..6b6fde86b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/glutin/src/api/egl/display.rs b/glutin/src/api/egl/display.rs index 0cae10d9b4..0e2ee62e38 100644 --- a/glutin/src/api/egl/display.rs +++ b/glutin/src/api/egl/display.rs @@ -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}; @@ -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 { @@ -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) }