diff --git a/src/kits/device/Joystick.cpp b/src/kits/device/Joystick.cpp index f91e0db457..016bfb1ebf 100644 --- a/src/kits/device/Joystick.cpp +++ b/src/kits/device/Joystick.cpp @@ -219,7 +219,8 @@ BJoystick::GetDeviceName(int32 index, char *name, size_t bufSize) if (fDevices == NULL) return B_NO_INIT; - if (index >= fDevices->CountItems()) + // CountDevices() also calls ScanDevices() and therefore updates our list. + if (index >= CountDevices()) return B_BAD_INDEX; if (name == NULL)