-
Notifications
You must be signed in to change notification settings - Fork 2
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
pong widget text askew #39
Comments
i started looking into this, it is probably related to my recent event changes. it appears that the animationFrame event triggers while the twrConDrawSeq is processing (or perhaps after if finished in the main thread, but before the worker thread process notification). I'll think on it and fix. |
upon further investigation, it appears that what is happening is this: When (the synchronous) twrConDrawSeq is called (the twrConDrawSeq was triggered by a the flush to measure text)., it waits on an event containing the return value (an internally generated event with no callback.) This is event is queued by JS thread when twrConDrawSeq completes in the JS thread. Then the worker thread then starts executing and starts processing the events. The way i implemented the recent event changes, the call back event are now processed before in returnvalue event. So the animationFrame callback is called before the twrConDrawSeq return event is processed (the events are processed out of order). the pong code does not handle this case. I can fix the event behavior so that no events are processed out of order, but I am wondering if there are other issues similar to this that won't be fixed. Before these recent changes, no callback events would be processed while waiting for a return value event. They were queued, but the callbacks didn't happen until after the return value was processed. The changes i made are to process callbacks while waiting for a return value event. You can see this behaviour in the timer example i committed, where repeating timer event callbacks are processed while twr_sleep is sleeping. Its a question of which behavior is desired. Any opinion? i'll think on it more. |
this is pretty complicated. What with nested blocking waits. Ie, a callback that is called while a a blocking wait is waiting, and the callback does a blocking wait. I restored events to the way they were before that work with pong (the events queue but don't callback if happening during a blocking wait). I am still thinking on if this is the permanent solution. |
reverted back to the prior method -- events queue up and are not processed during a blocking call like One could think of a blocking call like The main issue was that functions like So i will leave this open as an enhancement request -- Allow callbacks while blocking call is waiting? E.g |
I think allowing callbacks while a blocking calls are waiting could be fine. Though, with that implementation, it would be nice if blocking functions like Also, I've been looking back at the pong menu code and I'm not quite sure why a second call from animationFrame while the previous one is running would cause issues like that. I'm assuming the issue comes into play where I do canvas.measureText for the text in each of the buttons. So assuming that somehow 3 animationFrame events are called before the first one returns, I think the following would happen:
So, I can see how animationFrame being called multiple times could cause some issues for a few frames while everything is initializing, but I don't know why that would cause issues after that unless the subsequent calls to measureText were somehow mangled. Especially since the button it set to "initialized" before making any blocking calls, so it should be impossible for a subsequent call to enter the same initialization block while the other one is still blocked. Though, it is still possible that it can be fixed by having a simple guard variable that just returns from subsequent animationFrame calls if a previous one is still running. |
Windows, Chrome
If i run AI 2 player pong (regular), then the async version, sometimes i get text like this:
I did just change the way events work a bit. They now call the callback with less lag. I am not sure if that had an impact.
The text was updated successfully, but these errors were encountered: