Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: One controller counted as two BUG  (Read 3014 times)

0 Members and 1 Guest are viewing this topic.

TheWhiteGuy

  • Newbie
  • *
  • Posts: 4
    • View Profile
One controller counted as two BUG
« on: July 05, 2020, 12:47:58 pm »
Hi,
I'll start by saying, that I've already searched for the solution on the forum and google pretty thoroughly and no luck with finding it and I'm using SFML 2.5.1.

I'm making a game that uses two controllers and whenever I disconnect controller1 and reconnect it after everything works fine, but if I do the same with controller0 - controller1 quickly becomes controller1 and controller0 at the same time and reconnecting controller0 changes nothing and it's not even acknowledged anymore. I'm using JoystickDisconnected and JoystickConnected events in pollEvent loop

I've tried like everything:
- Joystick::update() in several places
- counting Joystick::getIdentification(i) where productId > 0
- additional bool variables
- additional loops
- Joystick::isConnected(i)
- additional pollEvent loop
- sleeping the thread for 100 and 1000 milliseconds
- all of above but in fuctions
and probably more, that I've already forgotten...

Atm my event handling looks like this:

                        if (event.type == Event::JoystickDisconnected)
                        {
                                if (event.joystickConnect.joystickId == 0)
                                {
                                        cout << "0 is disconnected" << endl;
                                        controller0 = false;
                                }
                                else if (event.joystickConnect.joystickId == 1)
                                {
                                        cout << "1 is disconnected" << endl;
                                        controller1 = false;
                                }
                                break;
                        }
                        if (event.type == Event::JoystickConnected)
                        {
                                if (event.joystickConnect.joystickId == 0)
                                {
                                        cout << "0 is connected" << endl;
                                        controller0 = true;
                                }
                                else if (event.joystickConnect.joystickId == 1)
                                {
                                        cout << "1 is connected" << endl;
                                        controller1 = true;
                                }
                                break;
                        }

                if (!controller0 || !controller1)
                {
                        this_thread::sleep_for(chrono::milliseconds(1000));

                        window.draw(rect, BlendNone);
                        window.draw(controllerDisconnectedSprite);
                        window.display();

                        continue;
                }

I can't really show you my previous attempts, but I can try to rewrite it if it's needed.

I've tried Windows settings too, but as expected it changes nothing. Controllers work fine outside of my game.

I'd really appreciate any help, cause I've been stuck with this for 3 days now.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: One controller counted as two BUG
« Reply #1 on: July 06, 2020, 11:57:46 pm »
We made a few adjustments for controller handling after SFML 2.5.1.
Can you grab the latest source code from GitHub and build SFML yourself?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

TheWhiteGuy

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: One controller counted as two BUG
« Reply #2 on: July 07, 2020, 11:46:37 am »
I'm using Visual Studio and I went for configured version and not Cmake. Do I just get newer version of folders I downloaded before and replace them?
« Last Edit: July 07, 2020, 11:48:15 am by TheWhiteGuy »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: One controller counted as two BUG
« Reply #3 on: July 07, 2020, 11:55:45 am »
In order to get the latest version, you need to use CMake and build your own version of SFML.
Once you have that, I'd suggest to either use a different folder or delete the existing files and copy in the newly built files.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

TheWhiteGuy

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: One controller counted as two BUG
« Reply #4 on: July 08, 2020, 08:50:56 pm »
Ok, I've been struggling with CMake for quite a while, but eventually I've managed to make it work, but the problem persists. Nothing's changed :/

TheWhiteGuy

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: One controller counted as two BUG
« Reply #5 on: July 08, 2020, 09:08:01 pm »
I've made an entirely new project that looks like this:

#include <iostream>
#include <SFML/Graphics.hpp>

using namespace sf;
using namespace std;

int main()
{
        sf::RenderWindow window(sf::VideoMode(800, 600), "window");

        sf::Event event;

        bool controller0;
        bool controller1;

        if (Joystick::isConnected(0))
        {
                controller0 = true;
        }
        if (Joystick::isConnected(1))
        {
                controller1 = true;
        }

        while (window.isOpen()) {

                while (window.pollEvent(event)) {

                        if (event.type == sf::Event::Closed) {

                                window.close();
                        }
                        if (event.type == Event::JoystickDisconnected)
                        {
                                if (event.joystickConnect.joystickId == 0)
                                {
                                        cout << "0 is disconnected" << endl;
                                        controller0 = false;
                                }
                                else if (event.joystickConnect.joystickId == 1)
                                {
                                        cout << "1 is disconnected" << endl;
                                        controller1 = false;
                                }
                                break;
                        }
                        if (event.type == Event::JoystickConnected)
                        {
                                if (event.joystickConnect.joystickId == 0)
                                {
                                        cout << "0 is connected" << endl;
                                        controller0 = true;
                                }
                                else if (event.joystickConnect.joystickId == 1)
                                {
                                        cout << "1 is connected" << endl;
                                        controller1 = true;
                                }
                                break;
                        }
                }
        }

        return 0;
}

Tested by:
1. Connecting c0
2. Connecting c1
3. Disconnecting c0

0 is connected
1 is connected
1 is disconnected
Failed to create DirectInput device: -2147467259
0 is disconnected
Failed to create DirectInput device: -2147467259
0 is connected

As you can see from console output, disconnecting c0 is recognized as disconnecting them both and reconnecting c0 after...

I've done some more tests and there is much more wrong going on including controller clonning as before :/

 

anything