vagran / dxf-viewer

DXF 2D viewer written in JavaScript
Mozilla Public License 2.0
295 stars 87 forks source link

Infinite loop when window.onmessage type doesn't match #8

Closed peternedap closed 2 years ago

peternedap commented 2 years ago

When the msg.data.type of a window.onmessage event does not match DxfWorker.WorkerMsg.LOAD or DxfWorker.WorkerMsg.DESTROY, DxfWorker._ProcessRequest will post a response that seems to retrigger the same error flow, resulting in an infinite loop.

This flow is triggered for me when using the webpack dev server, which posts a message when a hot reload is performed, as well as when using vue dev tools, which post a message when the plugin is initialized.

A possible solution to this would be creating a way to recognize onmessage events that are created by dxf-viewer so those from other sources can be ignored, maybe a message type prefix or a specific field in the data?

vagran commented 2 years ago

Thanks for the detailed report! I am currently enjoying COVID, so I hopefully will take a look a bit later.

vagran commented 2 years ago

I did not reproduce the reported behaviour but applied a fix to ignore messages originated by someone else as you suggested. It would be nice if you could check if it works for you.

peternedap commented 2 years ago

Thank you for your quick reply. The new version works for me :)

I would suggest changing

console.log(`Message with bad signature: ${msg}`)

to

console.log(`Message with bad signature:`, msg);

to prevent getting Message with bad signature: [object Object] messages

vagran commented 2 years ago

You are right, will fix it now.