-
Notifications
You must be signed in to change notification settings - Fork 912
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
Windows main thread ID check does not work when library is compiled as dylib + process is loaded with DLL injection #3999
Comments
What do you propose we do instead?
I no longer own a Windows machine, so I don't really know the details of DLLs, but could you show how that would work in Rust? |
Quite frankly I doubt there is a proper way to make this check work. At the end of the day this is at most a debug assert that hackily tries to replicate behavior that Windows does not have for very good reasons. I fully understand why winit tries but it's clear it's actually just not something that can ever be fully reliable. Personally I'm less of a perfectionist so I'd just remove it, but I'm assuming that won't fly I'd say at the very least:
For what it's worth this check would also break if you do something weird like compile your entire game to a library and then dynamically load it from some launcher application from another thread. Or something. I don't know why you would, but I think it's best nobody else has to lose sleep debugging this in the future.
That was just outlining how a DLL injection is generally done on Windows, it's not really something we need to care about. |
I guess another option (and certainly my preferred one) would be to turn it into a warning log, but I'm not sure if winit has a system for that? |
Sorry, I was confused how you were hitting this, since I misremembered how it works, but I now see that it's initialized by the system runtime. In any case, we do have If not, I'd be fine with making it a warning (via |
It does work, yes. I already set the relevant property in my Bevy project. I'm just filing this bug because I'm certainly not the last person that's going to get bitten and have to turn this on manually. More insidiously it's not impossible for somebody to publish a Bevy game in the future with dylib mode (in spite of this being recommended against) and then the game "works fine" and mysteriously breaks for users trying to run it with the Steam overlay. Not very pleasant to just have lurking in a library like this! |
Sounds good, I'll send a PR with that + putting it behind |
The check on Windows to enforce that the event loop is created from the main thread is not fully reliable (rust-windowing#3999). Given that this check is not necessary on Windows and only exists more as an assert to enforce platform consistency in development, I have made it more lax: * It now produces a tracing::warn!() message instead of an outright panic. * The check is only compiled in with cfg(debug_assertions)
Description
The Windows platform layer has a hacky method to infer the "main thread ID", to avoid people developing on Windows having their code not work on other platforms:
winit/src/platform_impl/windows/event_loop.rs
Lines 563 to 584 in f6b2085
This check does not work in the following scenario:
When winit is statically compiled into the main exe, this gets ran only from the actual CRT startup in the exe's main. But when the library is compiled into a dylib, the CRT actually calls it from DllMain. This doesn't normally matter because that usually goes hand in hand...
Except with the standard DLL injection technique (Steam, Renderdoc, ...): start the process suspended, run a new thread to load the injected DLL, resume the main thread. In this scenario, DllMain actually gets ran from the thread used to load the injected DLL, which is not the "main thread"...
Windows version
Winit version
0.30.5
The text was updated successfully, but these errors were encountered: