nefarius / ViGEmClient

ViGEm Client SDK for feeder development.
https://docs.nefarius.at/projects/ViGEm/
MIT License
134 stars 65 forks source link

Fixed crash on destructing NotificationRequestPool #6

Closed ttsuki closed 5 years ago

ttsuki commented 5 years ago

My application using ViGEmClient crashes when calling vigem_target_x360_unregister_notification().

When NotificationRequestPool::~NotificationRequestPool() calls CloseHandle(wait_handle),

in void NotificationRequestPool::operator()()

        // wait for the first pending I/O to signal its event
        const auto ret = WaitForMultipleObjects(
            requests_.size(),
            wait_handles_,
            FALSE, // first one to be signaled wins
            25 // don't block indefinitely so worker can be canceled
        );

returns WAIT_FAILED (0xFFFFFFFF).

Then

        // grab associated request
        const auto req = requests_[index].get();

with index = 0xFFFFFFFF causes a memory access violation.

I added some code checking whether WaitForMultipleObjects() returned WAIT_FAILED.

Another solution

Or calling NotificationRequestPool::terminate(); Sleep(100); from destructor before closing the handle also fixes the problem.

My build enviroment

Thanks,