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

vigem_target_x360_get_user_index returns wrong user index #31

@stephen9357

Description

@stephen9357

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions