I’ve got a really difficult problem.
I have built libusb with emscripten according to https://web.dev/articles/porting-libusb-to-webusb#build_system_and_the_first_test.
That all works great, with the test program provided, only problem I have now is I am trying to use this library with my own custom code but it is not working.
Very rough code
https://gitlab.com/-/snippets/4844863
I am compiling with this command:
EMCC_DEBUG=1 emcc main.c ./libusb/build/install-web/lib/libusb-1.0.a
-I./libusb/build/install-web/include
-L./libusb/build/install-web/lib
-s USE_PTHREADS=1
-s PTHREAD_POOL_SIZE=4
-s PROXY_TO_PTHREAD=1
-s ALLOW_MEMORY_GROWTH=1
-s ASYNCIFY=1
-s ENVIRONMENT=web,worker
-sASSERTIONS=2
--bind
-g3
-o main.html
Then I am hosting the file, using
const http = require('http');
const fs = require('fs');
const path = require('path');
http.createServer((req, res) => {
const filePath = path.join(__dirname, req.url === '/' ? '/main.html' : req.url);
fs.stat(filePath, (err, stats) => {
if (err || !stats.isFile()) {
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('404 Not Found');
return;
}
const ext = path.extname(filePath);
const contentType =
ext === '.js' ? 'application/javascript' :
ext === '.wasm' ? 'application/wasm' :
ext === '.html' ? 'text/html' :
'application/octet-stream';
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
res.writeHead(200, { 'Content-Type': contentType });
fs.createReadStream(filePath).pipe(res);
});
}).listen(8080, () => console.log('http://localhost:8080'));
When I visit the site, I get this error in chrome:
Hello, World!
(index):146 Found device 0451:e012
(index):146 Tkaksdf
VM1186:5 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'call')
at methodCaller<(int) => emscripten::val> (eval at __emval_get_method_caller (http://localhost:8080/main.js:5144:29), <anonymous>:5:17)
at __emval_call_method (http://localhost:8080/main.js:5015:14)
at imports.<computed> (http://localhost:8080/main.js:4747:24)
at main.wasm.emscripten::val emscripten::val::internalCall<(emscripten::internal::EM_METHOD_CALLER_KIND)0, emscripten::val, emscripten::val emscripten::val::call<emscripten::val, int&>(char const*, int&) const::'lambda'(emscripten::internal::_EM_METHOD_CALLER*, emscripten::_EM_VAL*, emscripten::internal::_EM_DESTRUCTORS**, void const*), int&>(emscripten::val emscripten::val::call<emscripten::val, int&>(char const*, int&) const::'lambda'(emscripten::internal::_EM_METHOD_CALLER*, emscripten::_EM_VAL*, emscripten::internal::_EM_DESTRUCTORS**, void const*), int&) const (http://localhost:8080/main.wasm:wasm-function[227]:0x264dd)
at main.wasm.int (anonymous namespace)::CachedDevice::awaitOnMain<int&>(char const*, int&) const::'lambda'()::operator()() const (http://localhost:8080/main.wasm:wasm-function[116]:0x142a7)
at main.wasm.(anonymous namespace)::em_set_configuration(libusb_device_handle*, int) (http://localhost:8080/main.wasm:wasm-function[114]:0x13a60)
at main.wasm.libusb_set_configuration (http://localhost:8080/main.wasm:wasm-function[66]:0x7244)
at main.wasm.usb_get_device (http://localhost:8080/main.wasm:wasm-function[48]:0x19e1)
at main.wasm.__original_main (http://localhost:8080/main.wasm:wasm-function[49]:0x29c9)
at main.wasm.main (http://localhost:8080/main.wasm:wasm-function[50]:0x2d2c)
No sure why, but it stops working in the function libusb_set_configuration
just wondering if anyone has any experience with this or could help guide me on how to debug this type of stuff. Thanks.