Fixed crash in the Linux implementation of Joystick, when inotify failed to initialize
This commit is contained in:
parent
5173f51d52
commit
c6767d0af1
@ -53,12 +53,19 @@ namespace
|
|||||||
|
|
||||||
bool canRead(int descriptor)
|
bool canRead(int descriptor)
|
||||||
{
|
{
|
||||||
fd_set set;
|
if (descriptor >= 0)
|
||||||
FD_ZERO(&set);
|
{
|
||||||
FD_SET(descriptor, &set);
|
fd_set set;
|
||||||
timeval timeout = {0, 0};
|
FD_ZERO(&set);
|
||||||
return select(descriptor + 1, &set, NULL, NULL, &timeout) > 0 &&
|
FD_SET(descriptor, &set);
|
||||||
FD_ISSET(notifyFd, &set);
|
timeval timeout = {0, 0};
|
||||||
|
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);
|
inotify_rm_watch(notifyFd, inputFd);
|
||||||
|
|
||||||
// Close the inotify file descriptor
|
// Close the inotify file descriptor
|
||||||
if (inputFd >= 0)
|
if (notifyFd >= 0)
|
||||||
::close(notifyFd);
|
::close(notifyFd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +127,7 @@ bool JoystickImpl::isConnected(unsigned int index)
|
|||||||
while (canRead(notifyFd))
|
while (canRead(notifyFd))
|
||||||
{
|
{
|
||||||
char buffer[128];
|
char buffer[128];
|
||||||
read(notifyFd, buffer, sizeof(buffer));
|
(void)read(notifyFd, buffer, sizeof(buffer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user