Skip to content

Joystick state does not update when polling events via RenderWindow on Windows #136

@caldur

Description

@caldur

Hi,

The joystick state does not seem to get updated properly on Windows.

According to the tutorial, "Joystick states are automatically updated when you check for events”, which I assume means that they got updated when the window is polling events. Doc on sfJoystick_update as well as the official sfml joystick example also work as suggested.

However when testing the following code with CSFML 2.5, calls to sfJoystick_isConnected always return false, unless I manually update the joystick state before the calls.

sfRenderWindow* window = sfRenderWindow_create(mode, "joystick test", sfClose, NULL);

  printf("Before polling:\n");
  for (int i = 0; i < sfJoystickCount; ++i) {
    // sfJoystick_update();
    sfBool connected = sfJoystick_isConnected(i);
    printf("%d: %d\n", i, connected);
  }
  
  printf("Polling starts:\n");

  while(sfRenderWindow_isOpen(window)) {
    sfEvent evt;
    while(sfRenderWindow_pollEvent(window, &evt)) {
      //sfJoystick_update();
      if (evt.type == sfEvtClosed) {
        sfRenderWindow_close(window);
        break;
      }

      else if (evt.type == sfEvtJoystickMoved) {
        //sfJoystick_update();
        unsigned int id = evt.joystickMove.joystickId;
        printf("%d: %d\n", id, sfJoystick_isConnected(id));
      }
    }
  }

I am building the above code with CSFML 2.5 64bit, mingw gcc 8.1 on windows 7. The joystick used is a compatible XBOX controller.
Similar code in c++ with SFML 2.5.1 runs without issue, however.
I also tested the code on mac and it worked as intended, so I'd suspect it's a windows only issue?

EDIT: Ok here is the funny part... when I changed window to regular sfWindow (instead of sfRenderWindow) I got the expected behavior.

Any insights would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions