Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is_loaded does not work on X11 (Linux) platforms #492

Open
khyperia opened this issue May 29, 2019 · 4 comments
Open

is_loaded does not work on X11 (Linux) platforms #492

khyperia opened this issue May 29, 2019 · 4 comments

Comments

@khyperia
Copy link

The world is a ball of sadness, and glXGetProcAddress never returns null. See point 3 in this page: https://dri.freedesktop.org/wiki/glXGetProcAddressNeverReturnsNULL/

As far as I can tell, gl::__::is_loaded() checks if the loading function returned null or not. As the X11 impl never returns null... is_loaded doesn't work as intended :'(

To be honest, I don't really care if this is somehow fixed or not (who actually uses is_loaded anyway), I'd be okay with a note on the readme or docs.rs front page saying "be careful with X11 and is_loaded, it probably doesn't do what you want".


Loading every function with the string "wow, this isn't the right string" returns some valid pointers 🌈

extern crate gl;
extern crate sdl2;

fn main() {
    let sdl = sdl2::init().expect("SDL failed to init");
    let video = sdl.video().expect("SDL does not have video");

    let window = video.window("test", 500, 500).opengl().build().expect("SDL window didn't build");
    let _gl_context = window
        .gl_create_context()
        .expect("Failed to create OpenGL context");

    gl::load_with(|_| video.gl_get_proc_address("wow, this isn't the right string") as *const _);

    if gl::GetError::is_loaded() {
        // Prints "Loaded." :sparkles:
        println!("Loaded.");
    } else {
        println!("Not loaded.");
    }

    unsafe {
        // Prints some random hecking number that I assume is uninitialized memory.
        println!("{}", gl::GetError());
    }
}

Non-minimized context that this bug report is from: https://twitter.com/khyperia/status/1133584256834215937

@khyperia
Copy link
Author

After rebooting into windows, that example outputs:

Not loaded.
thread 'main' panicked at 'gl function was not loaded', [blah blah]

as expected, because wglGetProcAddress returns null when passed an invalid string.

Well. On my system, it does. https://www.khronos.org/opengl/wiki/Load_OpenGL_Functions states "While the MSDN documentation says that wglGetProcAddress returns NULL on failure, some implementations will return other values. 1, 2, and 3 are used, as well as -1."

✨🌈 Thanks OpenGL! 🌈✨

@brendanzab
Copy link
Owner

arrrgh - any idea how we might be able to get around this?

@brendanzab
Copy link
Owner

Or are we doomed? 😭

@khyperia
Copy link
Author

My only thought is if the function data file (that I assume everything is generated from) includes extensions required - then it can check against glGetStringi(GL_EXTENSIONS, i). Alternatively/in addition to that, if the document specifies min version, get the version and do a comparison there.

That's a lot of work, though, so shrug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants