cntools / libsurvive

Open Source Lighthouse Tracking System
MIT License
747 stars 136 forks source link

Fix infinite loop in vive driver usb shutdown #313

Open Peaj opened 2 months ago

Peaj commented 2 months ago

Fixes infinite loop during vive driver shutdown. survive_handle_close_request_flag in drive_vive.c never shutdown the usb connection because usbInfo.requestClose was never true.

I updated survive_close_usb_device to set the requestClose flag to true so survive_handle_close_request_flag can react to it and close the connection.

I am not 100% sure where this flag is supposed to be set but from my understanding survive_close_usb_device should be reasonable and so far the plugin seems to shutdown gracefully.

Fixes #312

throni3git commented 2 months ago

i am getting into the libusb-side of the implementation, where there is a check for active_transfers before setting request_close. i am still trying to figure out how the whole ecosystem works, so maybe original contributors can give us a better insight on how this was planned...

in driver_vive.libusb.h in survive_close_usb_device at line 300 you'll find (for your considering)

    if (usbInfo->active_transfers == 0) {
        usbInfo->request_close = true;
        SV_VERBOSE(100, "Acking close for %s", survive_colorize_codename(usbInfo->so));
    }
Peaj commented 2 months ago

I did not look at libusb yet as I was building with the default setting of HIDAPI. The libusb implementation could bring insights into how it should be handled though. But dirver_vive.hidapi.h is not using active_transfers at all. I am not even sure when to user libusb over hidapi. Is hidapi a windows only thing?