nefarius / ViGEmBus

Windows kernel-mode driver emulating well-known USB game controllers.
https://docs.nefarius.at/projects/ViGEm/
BSD 3-Clause "New" or "Revised" License
3.08k stars 284 forks source link

Fix bug, if the plugin fails, the `VIGEM_TARGETS_MAX` device will be created. #54

Closed MiroKaku closed 3 years ago

MiroKaku commented 4 years ago

Hi,

Describe the bug Starting from the fifth ‘plugin’, countless devices will be created. (VIGEM_TARGETS_MAX 0xFFFF)

To Reproduce Run this:

int main()
{
    static const auto target_number = 5;

    const auto client = vigem_alloc();
    auto ret = vigem_connect(client);
    if (!VIGEM_SUCCESS(ret))
    {
        std::cerr << "vigem_connect() failed! ret: " << std::hex << ret << std::endl;
    }

    PVIGEM_TARGET targets[target_number] = { nullptr };

    for (auto i = 0u; i < target_number; ++i)
    {
        targets[i] = vigem_target_x360_alloc();

        ret = vigem_target_add(client, targets[i]);

        std::cerr << "vigem_target_add(" << std::dec << i << ") ret: " << std::hex << ret << std::endl;
    }

    // pause
    (void)getchar();

    for (auto i = 0u; i < target_number; ++i)
    {
        vigem_target_remove(client, targets[i]);
        vigem_target_free(targets[i]);
    }

    vigem_free(client);

    return 0;
}

Expected behavior Create 4 or 5 devices, But created countless. (VIGEM_TARGETS_MAX 0xFFFF)

Screenshots image

System details (please complete the following information):

nefarius commented 3 years ago

Thanks, I haven't forgotten to address this, just wanna give it the appropriate time to dig into the proposed changes. Bear with me please.

MiroKaku commented 3 years ago

Don't worry, I understand. Thank you for open source this project. 👍

nefarius commented 3 years ago

I can not reproduce the issue described on the latest development branch.

nefarius commented 3 years ago

Did further testing, I identified another issue, I can fix it in the upcoming v1.17 branch, sorry for the PR, bad timing 😅

MeeSong commented 3 years ago

on the master branch 😅

nefarius commented 3 years ago

The master branch is quite outdated though 🙁

MeeSong commented 3 years ago

Oh! I'm sorry. 😅

nefarius commented 3 years ago

At least on my end it seems to be working perfectly now using the latest v1.17 branch:

image

nefarius commented 3 years ago

This has been superseded by the changes introduced in v1.17.333.