-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Weird float arg bug on MicroPython when calling a JS method #1926
Comments
floats have been fixed recently in MicroPython but this is definitively a MicroPython issue. I am pinging @dpgeorge here as from our side there's not much we can do. As the linked live demo does not work for me (at all) it would be super nice if you could present just the minimal code that breaks, without involving any 3rd party library, something like a funciton that with 2 floats has issues ... that would surely help fixing the issue because ... well, all issues can be fixed, no need to be pessimistic 😉 |
I'm perplexed why my demo isn't working for you! That "glitch" only shows up when invoking that p5.Vector:set() method from that 3rd party library passing exactly 2 float arguments! Any other combination won't trigger that "very close to 0" bug. |
Thanks for the ping. I've managed to reproduce the issue with a simple |
Should be fixed in the latest version here: https://www.npmjs.com/package/@micropython/micropython-webassembly-pyscript/v/1.21.0-279 |
For historical reasons, I'm gonna leave 2 snapshots of my project showing the "glitch". It turns out, the current recommended version https://PyScript.net/releases/2023.11.1/core.js from https://PyScript.net is even worse, corrupting both My actual version comes from https://Unpkg.com/@PyScript/core, which always gets the latest. But I'm also gonna leave my 2nd snapshot using https://PyScript.net/releases/2024.1.1/core.js which corrupts only the 2nd |
I am going to update MicroPython in polyscript and bring that latest to PyScript too ... I will mention this issue to the team so that we can hopefully officially release a version that works sooner than later. Pinging @ntoll here too. |
this is why: works on Chrome, maybe Firefox (I haven't tried), fails on Safari / WebKit. As mentioned elsewhere, mime-type matters on the Web 😉 edit re-tested and now everything seems to be fine, even on WebKit, maybe a cache issue or maybe you changed something ... still it was a mime-type gotcha. |
The only file I've edited since opening this GH issue was "mpy.html" just a few hours, and only to add 2023.11.1 & 2024.1.1 Anyways, thx a lot every1 for taking care of this mysterious Python-to-JS 2 |
Happy to cut a release with this update. Please give me a 👍 @WebReflection and I'll make it so. |
@ntoll I'd like to have the currentScript story fixed in before ... otherwise I need to at least update polyscript to its latest as more got fixed in the meanwhile (config in workers as JSON not working) |
The latest MicroPython has landed officially so this bug should be solved now. |
Checklist
What happened?
On file "ball.py" from this project link:
https://PyScript.com/@gotoloop/bouncing-colorful-balls
https://GoToLoop.PyScriptApps.com/bouncing-colorful-balls/latest/mpy.html
This statement below produces an unexpected value for JS property
p5.Vector.y
:vel.set( p.random(-VEL, VEL), p.random(-VEL, VEL) )
Inspecting both props. x & y, former is OK, latter is buggy:
print('Bug:', vel.x, vel.y) # vel.x OK. vel.y either 0 or close to 0
These are my 2 workarounds:
Links to
p5.Vector.set()
's reference & implementation:https://p5js.org/reference/#/p5.Vector/set
https://GitHub.com/processing/p5.js/blob/v1.9.0/src/math/p5.Vector.js#L194-L215
Basically, the
p5.Vector.y
bug happens when we pass 2 float arguments top5.Vector.set()
.Here's a table describing all calling combinations for
p5.Vector.set(x, y, z)
:Changing to Pyodide on "mpy.html" fixes that bug:
<script type=py src=mpy.py config=mpy.toml></script>
Although it creates another 1, which is fixed by wrapping callback reset() w/ create_proxy().
This float bug is so bizarre that I fear it's almost unfixable!
What browsers are you seeing the problem on? (if applicable)
64-bit Win10 Chromium-based [120.0.6099.18] SlimJet [42.0.1.0]
Console info
Additional Context
No response
The text was updated successfully, but these errors were encountered: