Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web: canvas sharing #89

Open
konsumer opened this issue Nov 17, 2023 · 2 comments
Open

web: canvas sharing #89

konsumer opened this issue Nov 17, 2023 · 2 comments

Comments

@konsumer
Copy link
Contributor

konsumer commented Nov 17, 2023

In some code somewhere, the global canvas is being used, which requires this in host code, if you are not following all the assumptions emscripten makes:

window.canvas = canvas
// do stuff that interacts with pntr and hope that nothing else is doing same at same time

This shows up especially, if users are using mjs target, since it self-contains all the scope. A better way to do it, in my opinion, is to always use Module which is a global in single-wasm code, but exposed inside the closure-scope in emscripten-modules. For example, here, Module.canvas is better than canvas.

Essentially, in module-mode, it's possible to have multiple instances of the wasm, with their own memory and screen loading async, but in the current system, there is a potential race-condition, if 2 instances need canvas at the same time (because it's a global.)

You can see an example of that here. Even though each instance has it's own canvas, they cross on init, so it's possible they will use the same canvas instead of their own, and sometimes, when loading 2 web-components on the same page, it will grab the wrong canvas to draw on.

Related:

@konsumer
Copy link
Contributor Author

I think this is actually a problem with pntr_app. Essentially any use of canvas in a EM_JS should be Module.canvas.

@RobLoach RobLoach transferred this issue from RobLoach/pntr Jan 19, 2024
@RobLoach
Copy link
Owner

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants