0

I'm using GLFW to record the states of joysticks in a robotics project, and came across something strange.

On a Macbook Air, running 10.11.3, GLFW only returns the state of the joysticks at the beginning of the program. The documentation claims that it updates the state every time a joystick function is called, however. Using the joystick present and joystick name function only return the original state.

I cannot reveal my code. However, I am using ImGui, and one of it's sample programs should suffice. To reproduce the problem, run the 'opengl3_example' project with these changes:

Right after the line ImGui_ImplGlfwGL3_NewFrame();, add this:

for (int i = 0; i < 15; i++)
{
    if (glfwJoystickPresent(i) != GL_TRUE)
    {
        printf("There are %d joysticks detected.\n",i); break;
    }
}

In my case, if the program starts with no joysticks attached, and one is plugged in after the program has started running, it would claim that there would still be 0 joysticks attached. The problems run beyond that function, as the button and axis states are not updated as well.

I am using the latest GLFW 3.1.2, compiled from source. Please advise me on this.

EDIT: If you want to know what should happen, take a look at the video https://www.youtube.com/watch?v=mx0IUbxAQ34 on the 2:09 timestamp.

EDIT: I've tried a different library, and it detects the joysticks properly.

Thanks in advance.

hpm
  • 1,202
  • 13
  • 34
  • Does the axis and button states update correctly if the stick is attached PRIOR to running the program? – Richard Tyregrim Mar 08 '16 at 11:39
  • The axis states do not update correctly, in fact, at least for the first joystick detected by GLFW. It shows four axes in the array, all containing the float 138690176035340265469942380959367168.000000 or something very similar, always starting with 1386. All other axes for other joysticks are 0. During the program, the values never change or update. – hpm Mar 08 '16 at 11:51
  • 1
    Does the `joysticks` test have the same problem? – elmindreda Mar 08 '16 at 18:23
  • The `joysticks` test works, strangely. I tried importing the code into my C++ project, and it failed. I have no clue why this is, and can only think of two reasons: failure of my make system or no can do on C++. I will look into this further; help is appreciated. @elmindreda – hpm Mar 09 '16 at 12:41
  • OK, I found something new. If I compile the tests with the cmakelists.txt provided, the joysticks test works. If I type in cc `pkg-config --cflags glfw3` -o main joysticks.c ../deps/glad.c `pkg-config --static --libs glfw3` -I ../deps -DGLFW_TRUE=1 (sorry, I can't code format this), then the joysticks test fails. Any reason why that might happen? @elmindreda – hpm Mar 09 '16 at 22:50

1 Answers1

0

It turns out that the version of GLFW on homebrew is bugged. What an anticlimax.

For some reason, when I installed from source, it did not override homebrew's installed binaries. This led me to think it was a problem with code.

It wasn't.

hpm
  • 1,202
  • 13
  • 34