Fixed crash in the Linux implementation of Joystick, when inotify failed to initialize

This commit is contained in:
Laurent Gomila 2013-08-15 23:15:11 +02:00
parent 5173f51d52
commit c6767d0af1

View File

@ -52,6 +52,8 @@ namespace
}
bool canRead(int descriptor)
{
if (descriptor >= 0)
{
fd_set set;
FD_ZERO(&set);
@ -60,6 +62,11 @@ namespace
return select(descriptor + 1, &set, NULL, NULL, &timeout) > 0 &&
FD_ISSET(notifyFd, &set);
}
else
{
return false;
}
}
}
@ -102,7 +109,7 @@ void JoystickImpl::cleanup()
inotify_rm_watch(notifyFd, inputFd);
// Close the inotify file descriptor
if (inputFd >= 0)
if (notifyFd >= 0)
::close(notifyFd);
}
@ -120,7 +127,7 @@ bool JoystickImpl::isConnected(unsigned int index)
while (canRead(notifyFd))
{
char buffer[128];
read(notifyFd, buffer, sizeof(buffer));
(void)read(notifyFd, buffer, sizeof(buffer));
}
}