| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Thats odd, any idea why this is the case? |
Sorry, something went wrong.
|
(●__● ) great question, I have no idea |
Sorry, something went wrong.
|
oops I accidently attached the wrong issue - I meant #803 haha |
Sorry, something went wrong.
|
I think (please correct me if this is wrong):
Therefore, the correct fix may be to disable udev for windows builds only. WDYT? |
Sorry, something went wrong.
|
I was running it on Linux... |
Sorry, something went wrong.
Oh, the original issue was on windows |
Sorry, something went wrong.
|
@JonathanLeeIFX can you confirm if this fixes your issue on Windows? |
Sorry, something went wrong.
|
I'm not sure what the impact would be defaulting to not using udev. It seems a different source file is included: |
Sorry, something went wrong.
|
It's interesting that the example program did not work for you. It's supposed to be working because it only uses libusb. This fix did not work for me, but I may have done it wrong.
Output (edited for readability) device run 2: { |
Sorry, something went wrong.
|
Did you rebuild the binaries as well? Try the prebuild script, that's what I was using when testing it |
Sorry, something went wrong.
|
navigating to 'node_modules\usb' and running 'npm run prebuild' gives me the following error: > usb@2.13.0 prebuild gyp info it worked if it ends with ok gyp http GET https://nodejs.org/dist/v23.0.0/node-v23.0.0-headers.tar.gz |
Sorry, something went wrong.
|
hmm... Try to clone the repo, run prebuild and copy the prebuilds folder to your node_modules/usb folder |
Sorry, something went wrong.
|
I cloned the repo and it failed on 'npm install'. I had to copy the 'libusb' folder in from my original test repo. After that, 'npm install' worked. I then changed 'libusb.gypi' and 'binding.gyp', ran 'npm run prebuild', and copied 'prebuilds\win32-x64' to my test repo. |
Sorry, something went wrong.
|
I can't get it to work on windows either... On my Linux machine: import { getDeviceList } from "usb";
async function main() {
while (true) {
const allDevices = getDeviceList();
const device = allDevices.find(
(device) => device.deviceDescriptor.idProduct === <PID>
);
console.log(device?.deviceAddress);
await new Promise((resolve) => setTimeout(resolve, 1000));
}
}
main();Maybe this fix only works on linux? |
Sorry, something went wrong.
|
Possibly, but I'm still confused about the root issue: why does the node-usb package have an issue but not the original libusb DLL? |
Sorry, something went wrong.
|
Like I said in the PR, the original libusb DLL also didn't work for me |
Sorry, something went wrong.
|
@thegecko I think I found something (I don't know c++ that well, so please correct me if I get anything wrong). If I add libusb_unref_device right after constructing the device it works, but only until the device is garbage collected in js, libusb_unref_device is called again in the deconstructor and then this assert fails. If I remove the calls to libusb_ref_device in the constructor and libusb_unref_device in the deconstructor it works, but that's not a solution. And even after I do that is STILL doesn't work in linux unless I compile without udev |
Sorry, something went wrong.
I looked at this too, doesn't ref just add 1 and unref remove 1 meaning net zero overall? |
Sorry, something went wrong.
it starts at 1 ref |
Sorry, something went wrong.
then why does it get incremented in the constructor :/ |
Sorry, something went wrong.
|
I don't know man, maybe it was an oversight. If I had to guess it's because when the device is destroyed and not removed from the byPtr map it can cause some very weird behaviour in the get method. I added a log whenever a device was destroyed in the unref method, and it only ran whenever I didn't increment it in the constructor. |
Sorry, something went wrong.
|
Thanks for your help on this, I'll have a play around. This only fixes the windows issue, right? Linux is still tied up with udev. |
Sorry, something went wrong.
correct I pushed a potential fix. If the devices we actually unrefered at the end of GetDeviceList we won't be able to use them. so instead I temporarily unrefered them before calling libusb_free_device_list, then, I set the device pointer to the new pointer when getting the device. If a device still has a nullptr libusb device, it means the device no longer exists and we can delete it. We also can't use the pointer as the key in the byPtr map anymore as the pointer changes every time. What do you think? |
Sorry, something went wrong.
I don't think we can rely on this, I can imagine more odd edge cases than we have at the moment :/. Perhaps we should just recreate everything as soon as a GetDeviceList is called? |
Sorry, something went wrong.
That's not going to work is it? Any existing reads/etc. would break. I can't help feeling we are patching over and underlying issue here. We should be able to enumerate devices again while still holding references to them. What if we create a new usb context for getting a fresh list of devices then copy the changes over? |
Sorry, something went wrong.
How would we know what changed? how can we compare the devices and be certain they are the same physical device? |
Sorry, something went wrong.
|
Yeah you are right. Hmm. If we key based on libusb_get_device_address, I believe that's only unique per hub, so libusb_get_bus_number has to be in the key, too. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Changes
Compiling libusb without udev fixes the problem.
I tried running libusbTest from #803 (comment) and it didn't work either - unless I compiled libusb without udev.
Fixes
Checklist
Have you...