thegecko / webusb

Node.js implementation of the WebUSB Specification
https://thegecko.github.io/webusb/
MIT License
183 stars 27 forks source link

Crashes on Windows 7 64-bit (requestDevice) #68

Closed brandonros closed 4 years ago

brandonros commented 4 years ago
async getUsbDevice() {
    console.log('here')
    const device = await usb.requestDevice({
      filters: [
        {
          vendorId: VENDOR_ID,
          productId: PRODUCT_ID
        }
      ]
    })
    console.log('there')

there never gets printed

here
npm ERR! code ELIFECYCLE
npm ERR! errno 3221225477

node v12.18.1

windows 7 64-bit

webusb@2.0.2

brandonros commented 4 years ago
C:\Users\Brandon\Documents\GitHub\bash-uds-flasher\can-utils-js>npm install

> usb@1.6.3 install C:\Users\Brandon\Documents\GitHub\bash-uds-flasher\can-utils
-js\node_modules\usb
> prebuild-install --verbose || node-gyp rebuild

prebuild-install info begin Prebuild-install version 5.3.3
prebuild-install info looking for cached prebuild @ C:\Users\Brandon\AppData\Roa
ming\npm-cache\_prebuilds\579ac7-usb-v1.6.3-node-v72-win32-ia32.tar.gz
prebuild-install info found cached prebuild
prebuild-install info unpacking @ C:\Users\Brandon\AppData\Roaming\npm-cache\_pr
ebuilds\579ac7-usb-v1.6.3-node-v72-win32-ia32.tar.gz
prebuild-install info unpack resolved to C:\Users\Brandon\Documents\GitHub\bash-
uds-flasher\can-utils-js\node_modules\usb\build\Release\usb_bindings.node
prebuild-install info unpack required C:\Users\Brandon\Documents\GitHub\bash-uds
-flasher\can-utils-js\node_modules\usb\build\Release\usb_bindings.node successfu
lly

1
npm[7280]: c:\ws\src\node_buffer.cc:370: Assertion `(data) != nullptr' failed.
npm ERR! code ELIFECYCLE
npm ERR! errno 134
thegecko commented 4 years ago

Have you tried Node 10?

brandonros commented 4 years ago

Yes. The way you listUSBDevices is kind of bad.

try {
                e.configDescriptor, e.allConfigDescriptors, e.deviceDescriptor
            } catch (e) {
                return Promise.resolve(null)
            }

this code crashes all node.js versions on all windows version with a C++ segfault

commenting out e.allConfigDescriptors yields some succes

then when you open all devices in getCapabilities, that causes another segfault

i'm gonna have to fork this awesome library you did for my needs to just open USB devices matching filters

brandonros commented 4 years ago

can you pass options.filters all the way into

adapter

private loadDevices(filters): Promise<Array<Device>> {
        // Reset device cache
        this.devices = {};
        const devices = getDeviceList().filter(device => {

        })
        return this.serialPromises(this.loadDevice, devices);
    }

that will yield much better results for people on windows

thegecko commented 4 years ago

can you pass options.filters all the way into... loadDevices

I like that idea, see https://github.com/thegecko/webusb/pull/70

gniezen commented 4 years ago

So glad I came across this thread. I could not figure out why my code was working on MacOS and Linux, and then everything just crashes on Windows (7 and 10). For a couple of days I thought it was USB driver-related, so I've been trying WinUSB, libusbK etc.

Any idea when these changes will be out of preview @thegecko ?

thegecko commented 4 years ago

Any idea when these changes will be out of preview

Once I hear they have fixed the issue :) The preview is on npm here:

https://www.npmjs.com/package/webusb/v/2.0.3-next.0a3f331.0

gniezen commented 4 years ago

Well, they fixed they fixed the issue for me :+1: How about you @brandonros ?

brandonros commented 4 years ago

all good

gniezen commented 4 years ago

@thegecko Are you still waiting on something else to confirm that this is now fixed before the next release?

thegecko commented 4 years ago

Are you still waiting on something else...

My holiday to finish. I'm back now and have released v2.1.0

gniezen commented 4 years ago

Thanks @thegecko , hope you had a good holiday!