Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.

vigem_target_x360_get_user_index returns wrong user index #31

Open
stephen9357 opened this issue Jun 27, 2023 · 6 comments
Open

vigem_target_x360_get_user_index returns wrong user index #31

stephen9357 opened this issue Jun 27, 2023 · 6 comments

Comments

@stephen9357
Copy link

Describe the bug
Create and add four x360 devices to the bus, call vigem_target_x360_get_user_index to query the user index, it always returns 0.

To Reproduce
Steps to reproduce the behavior (example):
Compile and run this code.

int main()
{
    auto* client = vigem_alloc();
    if (!client) {
        cout << "Allocate client failed." << endl;
        return -1;
    }

    auto ret = vigem_connect(client);
    if (!VIGEM_SUCCESS(ret)) {
        cout << "Connect failed" << endl;
        vigem_free(client);
        return -1;
    }

    for (size_t i = 0; i < XUSER_MAX_COUNT; i++) {
        auto* xbox360 = vigem_target_x360_alloc();
        if (!xbox360) {
            cout << "Allocate xbox360 #" << i << " failed." << endl;
            continue;
        }

        ret = vigem_target_add(client, xbox360);
        if (!VIGEM_SUCCESS(ret)) {
            cout << "Add xbox360 #" << i << " failed." << endl;
            vigem_target_free(xbox360);
            continue;
        }

       ULONG index = 0xff;
        ret = vigem_target_x360_get_user_index(client, xbox360, &index);
        if (!VIGEM_SUCCESS(ret)) {
            cout << "Get user index #" << i << " failed." << endl;
            vigem_target_remove(client, xbox360);
            vigem_target_free(xbox360);
            continue;
        }
        cout << "#" << i << ": user index: " << index << endl;

        index = vigem_target_get_index(xbox360);
        cout << "#" << i << ": serial number: " << index << endl; 
    }

    vigem_disconnect(client);

    vigem_free(client);

    return 0;
}

Expected behavior
Output as below.
#0: user index: 0
#0: serial number: 1
#1: user index: 1
#1: serial number: 2
#2: user index: 2
#2: serial number: 3
#3: user index: 3
#3: serial number: 4

Screenshots
image

System details (please complete the following information):

Additional context
Add any other context about the problem here.

@nefarius
Copy link
Owner

This function never really was very reliable, it's timing sensitive due to the now aged code base that never really supported capturing the player index.

Here's a primitive test: add like a sleep 500 or greater after the plugin call and see if that changes things.

@stephen9357
Copy link
Author

stephen9357 commented Jun 27, 2023

add like a sleep 500 or greater after the plugin call and see if that changes things.

Thanks for your reply, it does't works. I add std::this_thread::sleep_for(std::chrono::seconds(10)); and XInputGetState before call vigem_target_x360_get_user_index, still returns 0.

@nefarius
Copy link
Owner

OK, hm, please subscribe to a EVT_VIGEM_X360_NOTIFICATION and print the LedNumber.

@stephen9357
Copy link
Author

subscribe to a EVT_VIGEM_X360_NOTIFICATION and print the LedNumber.

Thanks you very much, it works perfectly.

@nefarius
Copy link
Owner

subscribe to a EVT_VIGEM_X360_NOTIFICATION and print the LedNumber.

Thanks you very much, it works perfectly.

Great to hear! I guess figuring out what's wrong with the vigem_target_x360_get_user_index is still open, will leave the issue as a reminder for 2027 😬

@mpaperno
Copy link

Hi,

Strangely, and FWIW, vigem_target_x360_get_user_index() is working properly for me.

I haven't tried the repro example in the OP here (yet), but essentially I'm using it the same way -- vigem_target_x360_alloc() then vigem_target_add() and then get the LED number. The obvious differences are that:

  • I'm calling vigem_target_get_index() first, before vigem_target_x360_get_user_index() (I also call vigem_target_get_vid() and vigem_target_get_pid() first).
  • I'm not adding multiple devices in a tight loop (multiple, yes, but each is user-initiated).

(The full code is in here.)

I was a bit surprised when the resulting "user index" is zero-based, but it does increment for each new device, so I guess that's right.

Similar specs to the OP...

  • Windows 10 Pro, 22H2, 19045.3324 (also tested with some other Win10 installs)
  • ViGEm driver 1.21.442.0 from main GH project releases
  • ViGEm Client from latest master (no changes at all), x64 Release_LIB built with VS2022 (but keeping v142/VS2019 toolset), static link into another lib which is also built using v142/VS19 toolset.

LMK if any other details or info would be helpful.

Thanks for ViGEm!

-Max

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants