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

Most upvoted comments

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 directory Hopefully this fix addresses this issue as well.

Yep, increasing fs.inotify.max_user_watches fixed the issue. Thanks 😄

With cat /proc/sys/fs/inotify/max_user_watches I also get 8192.

The Atom Editor also complained about fs.inotify.max_user_watches and I get rid of the error by using there Troubleshooting: I tried it temporarly with: sudo sysctl fs.inotify.max_user_watches=32768 it worked and now I have made it permanent with: echo 32768 | sudo tee -a /proc/sys/fs/inotify/max_user_watches Increasing fs.inotify.max_user_watches fixes 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_watch fails with -1 flag. 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 seems ENOSPC (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 when fs.inotify.max_user_watches is exceeded. My system reports 8192 upon cat /proc/sys/fs/inotify/max_user_watches is executed. @thacoon, would you mind also trying this? Might be a good idea to look at the output of tail -f | dmesg for any additional reports by the system.

Also, please attempt increasing fs.inotify.max_user_watches temporarily 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 with inotify. Switching to libudev would 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 increase max_user_watches.

@thacoon try setting fs.inotify.max_user_watches=32768 in /etc/sysctl.d/99-sysctl.conf, should work for applying it permanently. Reload kernel parameters with sysctl --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 that glfwInit returns GLFW_TRUE, which is the correct behaviour. (even though the inotify_add_watch call fails with -1), 👍, just as you mentioned in the post above too, meaning _glfwInitJoysticksLinux did return GLFW_TRUE. The reason openJoystickDevice fails with GLFW_FALSE is because GLFW tries to open several devices under /dev/input prefixed with js (joystick), which might not be readable or of type block, open fails. Therefore, I think the behaviour of GLFW is correct here. What do you make of this @elmindreda? NOTE: @thacoon did glfwInit return GLFW_FALSE before? The results don’t match gdb here.

@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 so return -1; is not executed.

I did a quick search and GLFW_FALSE is returned by openJoystickDevice gdb_history.txt gdb.txt I am not sure if I did echo 8192 > /proc/sys/fs/inotify/max_user_watches because I have done some other things too, I’ll check.