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

Pyodide fatal error occurs in Pyxel on WASM #418

Closed
kitao opened this issue Sep 21, 2022 · 7 comments
Closed

Pyodide fatal error occurs in Pyxel on WASM #418

kitao opened this issue Sep 21, 2022 · 7 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@kitao
Copy link
Owner

kitao commented Sep 21, 2022

When Pyxel is running on Web, Pyodide reports a fatal error.

As far as I have investigated:

  • SDL2 on Emscripten throw 'unwind' exception when emscripten_set_main_loop is called. It's intentional. The purpose of it is to stop current code and continue infinite loop.
  • Pyodide catch every exception and report it as 'fatal error', and then throw it again.
  • As the result of that, Pyodide reports a fatal error when SDL2 started.

I will continue to investigate, but please let me know if there is a good solution.
One idea is to stop print fatal_error from Pyodide when the exception name is 'unwind' .

@kitao kitao added bug Something isn't working help wanted Extra attention is needed labels Sep 21, 2022
@kitao
Copy link
Owner Author

kitao commented Sep 21, 2022

@km19809 @laurentabbal

@kitao
Copy link
Owner Author

kitao commented Sep 21, 2022

Other idea is set the simulate_infinite_loop argument of emscripten_set_main_loop to false and handle infinite loop in Rust side though I'm not sure it is possible or not.

https://emscripten.org/docs/api_reference/emscripten.h.html

@km19809
Copy link
Contributor

km19809 commented Sep 21, 2022

Ok. As you mentioned, throwing an exception is intentional.
But the problem is, it is a Javascript Exception.
It can be handled neither by the rust side (It would not pass to the rust side) nor by the pyodide side (We need to modify it).
So I think simulate_infinite_loop = false is admirable.
Then the problem is the rust loop.
With the loop, it may block the browser (or may not. it should run the main loop asynchronously.).
Without the loop, it will terminate function and release variables (including VM).

So I will try simulate_infinite_loop = false and find ways to safely terminate the game loop.

@kitao
Copy link
Owner Author

kitao commented Sep 22, 2022

@km19809 I agree with you. simulate_infinite_loop = false looks good from the viewpoint of Pyodide execution.

In that case, the point is how to sleep for long time after emscripten_set_main_loop in Rust, I think.

I checked Emterpreter feature of Emscripten. It may be possible to realize sleep but its overhead is large.
I also read some article in which the author tried to run VIM on web.
He executed VIM in web worker and used Atomics.wait as sleep.
So if Pyxel and Pyodide executed in web worker and call Atomics.wait via emscripten_run_script. "Infinite sleep" can be realized.

This is my current hypothesis.

@kitao
Copy link
Owner Author

kitao commented Sep 23, 2022

Not the best solution, but I suppressed the uncaught exception error for an intentional 'unwind' exception from Emscripten by modifying Pyodide for now.

@km19809
Copy link
Contributor

km19809 commented Sep 28, 2022

I tested simulate_infinite_loop = false but it did not work as expected. It is hard to "sleep" yet.
I also tried emscripten_request_animation_frame_loop but the compiled code cannot find the signature of the function.
I cannot find why, but emscripten_request_animation_loop is not available now.
I am still investigating, but for now, modifying pyodide to ignore 'unwind' is the best solution.

@kitao
Copy link
Owner Author

kitao commented Oct 2, 2022

OK. Error itself is prevented now. So let me close this issue.
If there's any progress, let's open new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants