-
Notifications
You must be signed in to change notification settings - Fork 463
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
Fix version detection by calling GetVersion before GetWindowWMInfo #972
Fix version detection by calling GetVersion before GetWindowWMInfo #972
Conversation
One certain systems not doing this will cause a "Couldn't get SDL window info: Application not compiled with SDL 2.0" error.
the Otherwise we're good to go! |
True, but the |
@lewisclement I’m not at a computer until tonight, but I’ll check then :) Some context on why sdl2::raw_window_handle redefines a bunch of structs: the primary sdl2_sys module appears to be generated on a single platform, and using bindgen to get platform-specific bindings breaks code elsewhere. Basically it was going to be a breaking API change to support bindgen so I hardcoded the necessary structs instead. What you can probably do is implement Into for the hardcoded SDL_Version struct to turn it into the sdl2_sys struct. |
Wouldn't you encounter this specific problem in other places too then? Having each module redefine the types doesn't seem like a very efficient solution to me. |
It’s absolutely inefficient. Unfortunately the better solution was not the acceptable solution 🤷♀️ |
Your changes pull in the non cross-platform compatible sdl2_sys crate. It doesn't work on macos:
The bindings in sdl2_sys should only have ever been generated-only rather than checked into source control because of all the twiddles and knobs around features and platform compatibility. Unfortunately in the interest of not breaking anyone that uses what's currently there, the the raw-window-handle code rolls its own implementation of what it needs. If you're needing specific interop between the raw-window-handle code and the rest of the sdl2_sys crate, you'll have to add a translation function to convert between the structs. Lemme know if you need a hand with it, and I'm also available for macos-based testing. |
I ended up doing it the other way around, as copying the values wouldn't really get the desired result thanks to calling a method that takes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think macos is the oddball in this one by SDL_GetWindowWMInfo
working despite not checking the version number (it really should, and it's my bad for not doing it before anyway!) so it makes sense to grab it for all platforms, which the documentation subtly indicates should be done.
I also checked to see if the interleaving of dependencies on the sys
crate could be reduced, and it looks like all that's necessary to make this work is binding a local version of SDL_GetVersion that works with the rest of the local structs. The wm_info
struct is already mutable, which makes wm_info.version
mutable so no copying is necessary. Here's code changes:
// Make certain to retrieve version before querying `SDL_GetWindowWMInfo`
// as that gives an error on certain systems
unsafe {
SDL_GetVersion(&mut wm_info.version);
}
// ......
extern "C" {
fn SDL_GetVersion(ver: *mut SDL_version); // ADD THIS
fn SDL_GetWindowWMInfo(window: *mut SDL_Window, info: *mut SDL_SysWMinfo) -> SDL_bool;
}
The above works on both macos and arch.
Okay, that's roughly my first submission. But @Cobrand requested this to be changed. Or is that purely because we weren't yet aware why the types were redefined? |
Yeah I see that above. I think this should be done with a local bindings. The type conversion is pretty heavy and this is an "internally handled" call anyway so dealing with it in the context of a black box with no external dependencies makes sense. @Cobrand what do you think? |
Ideally we must avoid the
Why? Why not use Or perhaps I misunderstood something or I'm missing something? |
That's probably because of the derive of Default, which isn't in the |
If that's the only issue, finding a way to not use |
Yeah, that's what I figured too. I'm not really able to test anything on macos though, which seems to be the oddball here. @lmcgrath is the problem was that the Maybe let's apply it just to the SDL_version component. |
Does this last commit work for you, @lmcgrath ? |
I works for me! |
Looks good to me, anyone has anything else to add? |
…dle-version Fix version detection by calling GetVersion before GetWindowWMInfo
On certain systems not doing this will cause a "Couldn't get SDL window info: Application not compiled with SDL 2.0" error.