| Summary: | Replugging in “mixed” controller types crashes on macOS in SDL 2.0.13 | ||
|---|---|---|---|
| Product: | SDL | Reporter: | RustyM <rustym> |
| Component: | joystick | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | critical | ||
| Priority: | P2 | CC: | matpow2 |
| Version: | 2.0.13 | ||
| Hardware: | x86 | ||
| OS: | Mac OS X (All) | ||
|
Description
RustyM
2020-06-16 01:30:58 UTC
The while loop in FreeDevice() assumes that every device is not NULL.
recDevice *device = gpDeviceList;
while (device->pNext != removeDevice) {
device = device->pNext;
}
device->pNext = pDeviceNext;
So maybe we should check for NULL here? Or instead prevent adding NULL devices to the list in the first place? Checking device for NULL before entering the loop appears to work.
recDevice *device = gpDeviceList;
if (!device) {
while (device->pNext != removeDevice) {
device = device->pNext;
}
}
device->pNext = pDeviceNext;
I don’t really understand how SDL is tracking devices, so I suspect this is a naive solution. This seems to fix the crash, but I fear we are no longer freeing a device or doing something else horrible.
Also I apologize if this bug shouldn’t be marked “critical”. I chose it because Bug 5034 was marked the same way.
Looks like we have reproduced this same issue on 2.0.14 on Mac with a PS5 and Nintendo Switch Pro Controller.
This might be caused by the early FreeDevice calls in JoystickDeviceWasAddedCallback before the device is added to the global device list gpDeviceList.
This will likely cause FreeDevice to crash, since it will never find the device in the global device list:
while (device->pNext != removeDevice) {
device = device->pNext;
}
Fixed, thanks! https://hg.libsdl.org/SDL/rev/b1d2cb0484aa |