Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joystick won't update without Joystick.Update() even when calling window.DispatchEvents() #189

Open
andre-sampaio opened this issue Jun 30, 2020 · 2 comments
Labels

Comments

@andre-sampaio
Copy link

Despite polling window events the Joystick status is not updated unless explicitly calling Joystick.Update().

Minimal working sample (with one joystick connected):

        static void Main(string[] args)
        {
            var window = new RenderWindow(new VideoMode(200, 200), "Joystick doesn't read :(");
            
            while (window.IsOpen)
            {
                window.DispatchEvents();

                Console.SetCursorPosition(0, 0);

                for (uint i = 0; i < Joystick.Count; i++)
                {
                    var isConnected = Joystick.IsConnected(i);
                    Console.WriteLine($"{i}: {isConnected}");
                }
            }
        }

Expected result: One joystick is connected
Actual result: No joystick connected

Calling Joystick.Update before the loop will update the joystick status and will achieve the desired result.

The same applies to actually getting the Joystick state:

        static void Main(string[] args)
        {
            var window = new RenderWindow(new VideoMode(200, 200), "Joystick doesn't read :(");
            Joystick.Update();

            uint connectedJoystick = 0;
            for (uint i = 0; i < Joystick.Count; i++)
            {
                var isConnected = Joystick.IsConnected(i);
                if (isConnected)
                    connectedJoystick = i;
            }

            while (window.IsOpen)
            {
                window.DispatchEvents();

                Console.SetCursorPosition(0, 0);

                for (uint i = 0; i < Joystick.AxisCount; i++)
                {
                    var position = Joystick.GetAxisPosition(connectedJoystick, (Joystick.Axis)i);
                    Console.WriteLine($"Axis {(Joystick.Axis)i}: {position}");
                }
            }
        }

Expected behavior: Axis position gets tracked accordingly to controller
Actual behavior: All axis values stuck

Again, calling Joystick.Update() inside the event loop will update the values correctly.

IDE: Visual Studio 2019
.Net SDK: .NET Core 3.1.301
Platform: x64
Configuration: Debug
OS: Windows 10

@andre-sampaio
Copy link
Author

After building CSFML locally and using this DLL instead of the one from Nuget the code started to work as expected, updating the controller status without needing to call Joystick.Update(). But if I go back to the Nuget version of SFML it stops working again.

I'll try to investigate this a bit more over the weekend, but it looks somehow related to CSFML Nuget package.

@andre-sampaio
Copy link
Author

After taking a look at the build file for CSFML Nuget package, I noticed that the package is linking statically to SFML. After building it statically I was able to reproduce the error.

Since this is clearly related to CSFML I'll open this issue over there.

@eXpl0it3r eXpl0it3r changed the title Joystic won't update without Joystick.Update() even when calling window.DispatchEvents() Joystick won't update without Joystick.Update() even when calling window.DispatchEvents() Jun 15, 2023
@eXpl0it3r eXpl0it3r added the Bug label Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants