armory icon indicating copy to clipboard operation
armory copied to clipboard

Web workers do not work on Krom

Open QuantumCoderQC opened this issue 2 years ago • 0 comments

Web workers do not work on Krom, whereas, works as expected on HTML5.

Description As a test, I used a simple JS file and created a worker thread with it. I then do a postMessage on the thread and listen for any events from the worker.

The JS script looks like so:

onmessage = function(message){
    console.log("hi from JS");
    let x = 10;
    self.postMessage(x);
}

And the Haxe script looks like so:

package arm;

class MyTrait extends iron.Trait {
	public function new() {
		super();

		notifyOnInit(function() {
			var worker = new js.html.Worker('testscript.js');
			trace(worker);
			worker.addEventListener("message",function (data:Dynamic){
				trace("Event !");
				trace(data.data);
			});
			worker.postMessage("Hello");
			
		});
	}
}

When run, I get the following output on HTML5:

Log.hx:66        arm/MyTrait.hx:9: [object Worker]
testscript.js:2  hi from JS
Log.hx:66        arm/MyTrait.hx:11: Event !
Log.hx:66        arm/MyTrait.hx:12: 10

And below is the output on Krom:

arm/MyTrait.hx:9: {

}

Some more info:

  1. Basic web workers on Krom were implemented here: https://github.com/armory3d/armorcore/pull/19
  2. Krom is already built with WITH_WORKER enabled.

To Reproduce Run the provided test file on Krom and on HTML5 (Browser)

Expected behavior Web workers should work on krom.

System Blender: 2.93 Armory: 2022.08 OS: Windows

Test File KromWorkerTest.zip

QuantumCoderQC avatar Aug 26 '22 21:08 QuantumCoderQC