| Summary: | SDL_PollEvent does not return after restarting the program a few times | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Daniel <danielmott852> |
| Component: | *don't know* | Assignee: | Ryan C. Gordon <icculus> |
| Status: | WAITING --- | QA Contact: | Sam Lantinga <slouken> |
| Severity: | major | ||
| Priority: | P2 | CC: | danielmott852, metalcaedes, sezeroz |
| Version: | 2.0.9 | ||
| Hardware: | x86_64 | ||
| OS: | Windows 10 | ||
| Attachments: | Code I used to test the bug. | ||
|
Description
Daniel
2018-11-17 03:32:16 UTC
What's the stack trace where it's hung up? You're not initializing the joystick subsystem, so that shouldn't be a factor here. I am not exactly sure if this is the stack trace you are looking for, but here is the call stack when the application locks up. https://i.gyazo.com/f8aa8661e2b8adb10d0138e3c9ecffd1.png Can you build SDL yourself so you can get symbols for that stack trace? (In reply to Sam Lantinga from comment #3) > Can you build SDL yourself so you can get symbols for that stack trace? Here is the stack trace with symbols. I used the code currently available on the repo. https://i.gyazo.com/820e525a33ac0d56266d03fee4263635.png It appears to get stuck on hid_enumerate() in the HidD_GetSerialNumberString function call. Can you try if it works if you pass SDL_INIT_JOYSTICK to SDL_Init()? In https://discourse.libsdl.org/t/since-2-0-9-game-freezes-every-few-minutes-on-win7/25318 it turned out that SDL_PumpEvents() calls SDL_JoystickUpdate() (which then eventually causes hid_enumerate() to be called) even if joysticks are not enabled. However, if they are not enabled SDL_HIDAPI_discovery.m_bCanGetNotifications is false and thus every three seconds the HID devices are updated (instead of only when a corresponding event arrives). If this indeed is related to my problem discussed in discourse, I could fix that by modifying SDL_PumpEvents() to only call SDL_JoystickUpdate() if joysticks are actually enabled, like
/* Check for joystick state change */
if (SDL_WasInit(SDL_INIT_JOYSTICK) && (!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || SDL_JoystickEventState(SDL_QUERY))) {
SDL_JoystickUpdate();
}
I wonder if the same should be done a few lines below for the sensors, i.e. adding a SDL_WasInit(SDL_INIT_SENSORS) to the if-condition before SDL_SensorUpdate();
I also don't know if SDL_WasInit() is indeed the best/most efficient way to test this, or if maybe some other flag should be checked at the beginning of SDL_JoystickUpdate() instead (and then return immediately there), but apart from these details, we need to make sure that SDL_JoystickUpdate() doesn't try to enumerate HID devices if joysticks are disabled.
Passing SDL_INIT_JOYSTICK, with and without other conditionals, into SDL_Init() does not appear to fix the issue. Previously, the window would appear, then the program would hang on SDL_PollEvent with a white and unresponsive window after a few launches. With SDL_INIT_JOYSTICK, the window never even shows up because the program hangs on SDL_Init() after a few launches. Note: After the program freezes once, I am unable to get it to work correctly again unless I reboot my machine. Adding/removing SDL_INIT_JOYSTICK from SDL_Init() after the program has started freezing does not appear to do anything either. Ok, that indicates that on your machine everything is a lot more broken then on mine - here hid_enumerate() sometimes takes 5seconds which is a lot longer than usual, but apparently on your machine it locks up completely and even manages to get some internal state of windows/the driver/the device so confused that you need to reboot before they can be queried again. So this definitely needs more investigation by someone who knows about such things - I don't, but to me it seems like it could totally be a hardware or driver or maybe windows problem. Of course it /could/ still be that SDL does something wrong when querying the devices, but even if it does, being executed in an unprivileged process it shouldn't be able to screw things up in a way that need a reboot. I created a new bugreport for my issue: #4391 Can you check to see if this change helps? https://hg.libsdl.org/SDL/rev/9091b20040cf Thanks! Also, can you get a list of USB devices that are connected, and try unplugging them all and then add them one by one until this breaks? This seems to be a bug in the Windows USB driver system and it would be nice to know what's triggering it. Thanks! I will work on testing that change and getting a list of USB devices. I will also test the bug on my laptop, once using 2.0.9, and another time using the change you suggested. The fix you suggested does appear to have worked. I have not been able to reproduce the bug on my desktop or laptop. Switching between my desktop and laptop(running out-of-date windows) did not appear to make a difference while testing the latest stable release(2.0.9) or the fix you suggested. Version 2.0.9 caused the program to freeze on both machines. The fix appeared to have worked on both machines. If you are unfamiliar with Windows, the grayed out items are inactive devices. USB Devices on Desktop: https://i.gyazo.com/5b00c74e6451ba3982de2d9e2b124a40.png USB Devices on Laptop: https://i.gyazo.com/c17e85d46b8b90e29fc908c17727fe53.png Let me know if you want information on a specific device. Does that commit also fix the issue for you if you use SDL_INIT_JOYSTICK? If I recall correctly, just querying the devices once on startup can already permanently freeze your program, and of course SDL should also work with joysticks enabled. The issue still exists while using SDL_INIT_JOYSTICK. One thing that did change, however, is that I no longer have to reboot my machine to get the program to work again after switching from using SDL_INIT_JOYSTICK to not using it. Previously if the program froze while using SDL_INIT_JOYSTICK, the program would continue to freeze even without using SDL_INIT_JOYSTICK. If the program froze while not using SDL_INIT_JOYSTICK, the program would also continue to freeze when using it. From the device list it looks like you don't have any active USB devices - is that right? It shouldn't be possible for the Windows driver to hang with no devices on the USB bus. If you do have USB devices connected, can you remove them and see if that fixes the issue for you, and if no, remove them one at a time to see if it's a particular device that's causing the problem? Note that this could even be keyboard/mouse (if they're connected via USB), so in that case use a different one - ideally use an old PS/2 keyboard, if you've still got one and your mainboard still has a connector for that. (though maybe for testing you could start your test app with just keyboard or mouse and the other one disconnected) Can you check to see if this is fixed in the latest SDL snapshot? http://www.libsdl.org/tmp/SDL-2.0.zip Thanks! |