microsoft / GDK

Microsoft Public GDK
http://aka.ms/gamedevdocs
Other
1.48k stars 99 forks source link

Can't get fresh readings. #64

Open Gavin-Williams opened 3 months ago

Gavin-Williams commented 3 months ago

Calling GetCurrentReading and checking the timestamp shows that it's the same reading over and over again. I can't get fresh readings.

    public static string GetReading()
    {
        IntPtr readingComPtr = InteropGameInput.GetCurrentReading(InputKind.Mouse, IntPtr.Zero);
        IGameInputReading reading = (IGameInputReading)Marshal.GetObjectForIUnknown(readingComPtr);

        ulong t = reading.GetTimestamp();
        string result = readingComPtr.ToString() + " | " + t.ToString();

        Marshal.FinalReleaseComObject(reading);
        return result;
    }
Input.Create | result = S_OK
Input.Time      readingCmpPtr | reading.Time
547322007323    2074475510032 | 547321957562
547322042057    2074475506032 | 547321957562
547322076200    2074475509392 | 547321957562
547322110489    2074475506752 | 547321957562
547322144683    2074475510112 | 547321957562
547322178827    2074475509232 | 547321957562

The ref count for reading is zero. How can I be getting the same reading repeatedly, if it's being destroyed every frame?

bbowman commented 2 months ago

Hey @Gavin-Williams, sorry for the long delay on any response here. I am not a member of the GameInput team but I saw your issue and may be able to help at least a little.

Game Input's GetCurrentReading api will return the most recent reading from the device and if the mouse hasn't moved or a button hasn't been clicked, no new reading will be produced. In terms of the COM ref counting you mention, this does not cause a 'new' reading to come through the system. You may be releasing your view of the current reading and that will destroy the object but calling GetCurrentReading will just create a new COM object based off the same most reading from the device so its not really signaling anything to system to 'move on'.

If you are still experiencing issues here, and can help explain more about your situation (my guess that mouse isn't changing for instance could be way off base for what you are seeing locally), then I might be able to get you some more specific help.

bbowman commented 2 months ago

See https://github.com/microsoft/GDK/discussions/62 for more information.