c++ - SDL2 joystick event not triggering -


so i've got code:

void engine::run() {     // initialize components     if (sdl_init(sdl_init_video | sdl_init_joystick))         throw exception("couldn't initialize sdl\n" + string(sdl_geterror()), 1);      // other code      run = true;     sdl_event event;      while (run) {         // other code          uint32 timeout = sdl_getticks() + 50;         while (sdl_pollevent(&event) && timeout - sdl_getticks() > 0)             handleevent(event);     } }  void engine::handleevent(const sdl_event& event) {     switch (event.type) {     case sdl_keydown:         inputsys->keydownevent(event.key);         break;     case sdl_keyup:         inputsys->keyupevent(event.key);         break;     case sdl_joybuttondown:         cout << "button" << endl;         break;     case sdl_joyhatmotion:         cout << "hat" << endl;         break;     case sdl_joyaxismotion:         cout << "axis" << endl;         break;     case sdl_joydeviceadded: case sdl_joydeviceremoved:         inputsys->updatecontrollers();         break;     // other code     } } 

the problem events aren't being called, joystick button, hat , axis events. other 2 joystick related events work fine.
i'm using exact same code in different project, joystick events called without issue, since moved code new project, don't called anymore.
sdl recognize plugged in controller , can use functions sdl_joystickgetaxis, reason these 3 events don't seem working. idea why is?

you have call sdl_joystickopen events. here's example:

sdl_joystick *joy;  // initialize joystick subsystem sdl_initsubsystem(sdl_init_joystick);  // check joystick if (sdl_numjoysticks() > 0) {     // open joystick     joy = sdl_joystickopen(0);      if (joy) {         printf("opened joystick 0\n");         printf("name: %s\n", sdl_joysticknameforindex(0));         printf("number of axes: %d\n", sdl_joysticknumaxes(joy));         printf("number of buttons: %d\n", sdl_joysticknumbuttons(joy));         printf("number of balls: %d\n", sdl_joysticknumballs(joy));     } else {         printf("couldn't open joystick 0\n");     }      // close if opened     if (sdl_joystickgetattached(joy)) {         sdl_joystickclose(joy);     } } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -