glfw: Failed to initialize GLFW: failed to watch joystick
Hi,
I have installed glfw and I get the following error:
Linux: Failed to watch for joystick connections in /dev/input: No space left on device
glfwInit() fails to initialize without joystick support.
I am using Arch Linux (linux 4.7-1) and I have installed glfw-x11 (3.2-4) via pacman. I have also tried to solve this problem by compiling the stable version 3.2.
I can run it without error when running as sudo.
This is the code I am running:
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h> //on Arch: glfw-x11
#include <glm/glm.hpp>
void error_callback(int error, const char* description)
{
puts(description);
}
int main(int argc, char *argv[])
{
glfwSetErrorCallback(error_callback);
// Initialise GLFW
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
return -1;
}
return 0;
}
I have just found one similar issue, but for go-gl: Can not initialize GLFW without joystick support
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 19 (5 by maintainers)
Commits related to this issue
- Linux: Make joystick init always fail silently Related to #833. — committed to glfw/glfw by elmindreda 7 years ago
- Linux: Make joystick init always fail silently Related to #833. — committed to glfw/glfw by elmindreda 7 years ago
A similar issue affects GLFW initialization on Windows Subsystem for Linux. At this time WSL does not provide “/dev/input”. GLFW initialization fails with error:
Failed to watch for joystick connections in /dev/input: No such file or directoryHopefully this fix addresses this issue as well.Yep, increasing
fs.inotify.max_user_watchesfixed the issue. Thanks 😄With
cat /proc/sys/fs/inotify/max_user_watchesI also get8192.The Atom Editor also complained about
fs.inotify.max_user_watchesand I get rid of the error by using there Troubleshooting: I tried it temporarly with:sudo sysctl fs.inotify.max_user_watches=32768it workedand now I have made it permanent with:echo 32768 | sudo tee -a /proc/sys/fs/inotify/max_user_watchesIncreasingfs.inotify.max_user_watchesfixes it but making it permanent does not work, I have to increase it after every reboot.Seems the error originates from glfwInitJoysticksLinux, whenever
inotify_add_watchfails with-1flag. I’m not experiencing these issues myself, and I’m sitting on the exact same setup as you @thacoon. So, according to the manual/posts referenced below, it seemsENOSPC(The user limit on the total number of inotify watches was reached or the kernel failed to allocate a needed resource) was triggered. Which has primarily been caused whenfs.inotify.max_user_watchesis exceeded. My system reports8192uponcat /proc/sys/fs/inotify/max_user_watchesis executed. @thacoon, would you mind also trying this? Might be a good idea to look at the output oftail -f | dmesgfor any additional reports by the system.Also, please attempt increasing
fs.inotify.max_user_watchestemporarily by issuing a higher value for it e.g.echo 16384 > /proc/sys/fs/inotify/max_user_watches(won’t be permanent, so no worries 😉). Then attempt initializing glfw again, and report your results. This isn’t a fix, but it might help debugging it. However tbh, if this is the cause of the problem, I have no idea how GLFW will be able to handle it, since joystick connections are currently monitored withinotify. Switching tolibudevwould probably fix this but would add an extra library dependency on GLFW, which probably isn’t very good idea, in my opinion. Also seems like other projects with the same issues just recommend users increasemax_user_watches.@thacoon try setting
fs.inotify.max_user_watches=32768in/etc/sysctl.d/99-sysctl.conf, should work for applying it permanently. Reload kernel parameters withsysctl --system. From the Arch Wiki.EDIT: also, could you close this issue since it seems to have been resolved? (less work for maintainers).@rrika Oops, I was sure I’d fixed that. It should be fixed now with a397195d3fd14b3e94026bce684e6b5f392f5015. Thank you!
Thanks for the information @thacoon! Based on the output of
gdb.txt, it seems thatglfwInitreturnsGLFW_TRUE, which is the correct behaviour. (even though theinotify_add_watchcall fails with-1), 👍, just as you mentioned in the post above too, meaning_glfwInitJoysticksLinuxdid returnGLFW_TRUE. The reasonopenJoystickDevicefails withGLFW_FALSEis because GLFW tries to open several devices under/dev/inputprefixed withjs(joystick), which might not be readable or of type block,openfails. Therefore, I think the behaviour of GLFW is correct here. What do you make of this @elmindreda? NOTE: @thacoon didglfwInitreturnGLFW_FALSEbefore? The results don’t matchgdbhere.@CaffeineViking I am currently not at home, it may take a few days before I can answer again. I’ll do it as soon as I am back home. I could reproduce the issue on my netbook.
I noticed that when I am compiling the code above without
glfwSetErrorCallback(error_callback);the if statement is not called and soreturn -1;is not executed.I did a quick search and
GLFW_FALSEis returned byopenJoystickDevicegdb_history.txtgdb.txtI am not sure if I didecho 8192 > /proc/sys/fs/inotify/max_user_watchesbecause I have done some other things too, I’ll check.