Trying webworker sample, no console output...
Entered the examples, tried running locally & on remote web server, web page loads, javascript loads, no console output...
14 Replies
Can you clarify which product and what example are you following?
Leaning Technologies Developer Hub
Threading with Web Workers - Cheerp Documentation
Cheerp is an enterprise-grade compiler toolchain that can compile C/C++ into efficient WebAssembly and JavaScript. It is open source, liberally licensed, and actively developed by Leaning Technologies.
Please share what you have in the console log
And network tab as well,to make sure the code can be loaded
% /Applications/cheerp/bin/clang++ --version
Cheerp 3.0 clang version 16.0.0 (https://github.com/leaningtech/cheerp-compiler 29e4600563ed2153faf0221362ce4f0a5b93e1ce) Target: cheerp-leaningtech-webbrowser-wasm Thread model: posix InstalledDir: /Applications/cheerp/bin
Cheerp 3.0 clang version 16.0.0 (https://github.com/leaningtech/cheerp-compiler 29e4600563ed2153faf0221362ce4f0a5b93e1ce) Target: cheerp-leaningtech-webbrowser-wasm Thread model: posix InstalledDir: /Applications/cheerp/bin
I meant the devtools console
Console is totally empty
Got the other examples working
Check the network tab
Can you confirm both javascript files are loaded?
In debugging it, breakpoints added at the addEventListener calls are reached
Ah... interesting, IMO: console in the 'worker.js' file shows the "Hello World" output, not visible from loading the index.html
Wait, apparently not not working again... had it call the event listener once while debugging though!?
Hmm; if I set a breakpoint right on the 'console.log' call, it is reaching there, and if I single step over, it shows up in the console, but otherwise mostly not (?).
Yes, for some reason single stepping from the addEventListener() calls causes the console.log() call to be eventually reached, otherwise generally not (!?).
WTF?
The docs example is incorrect, we need to fix this
The underlying problem is that the worker can lose messages since compiling wasm code is asynchronous
This is a general web worker issue, not connected to Cheerp, but the example needs to be modified to take that into account
Please try with the following modified sources:
cheerpWorkerHost.cpp
cheerpWorker.cpp
The idea for the new approach is to wait for the worker to be ready before attempting to send an actual message. The first null message is interpreted as "ready" message.
@Chen Please devise a better example for the worker docs and update labs accordingly
Reported on github issues also, with reply showing compiler ~"error: variable 'w' cannot be implicitly captured in a lambda with no capture-default specified w->postMessage(String("Hello World"));"...
Simply add
w
to the capture list, apologies for the mistake
Hmmm.. Actually the code above includes the [w]
as expected
I think you might have updated the lambda body, but not the whole codeAh, yes, you are correct (Ops, sorry about my part in that!) : I just pasted in the apparent body change, missing the [w]... The altered code does appear to be producing the dual "Hello World" console result in my Safari and FireFox browsers, but now gives an error in Chrome saying ~"worker.js:1 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'buffer') at worker.js:1:1143", hiliting the " heap = asm.W.buffer;" line.
Hmm... although I had reloaded & hit the option-reload button, now I explicitly selected the menu for a forced 'empty cache and hard reload', and Chrome appears to be 'working' also!?
Glad to hear the test now works for you. We will take care of fixing the docs, thanks for reporting this.