-
Notifications
You must be signed in to change notification settings - Fork 25
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
Scripts run 3 times on windowed mode #247
Comments
With this script print(colormode())
colormode(HSB)
print(colormode()) I get this output: rgb
hsb
hsb
hsb
hsb
hsb The variables aren't reset between runs, which is not good. |
However, with this print(colormode())
def setup():
colormode(HSB)
print(colormode()) gives rgb
hsb
hsb
hsb I have absolutely no clue what's going on here! |
Obviously having output 3x is wrong. As for colormode being persistent, I would run this in nodebox1 before being sure it's a bug. |
The bit of code that does the running is a bit complex, (and needs some tests). Our suspects all live in grammar.py in the Grammar class:
One thing this looks at is self._dynamic - which is set if the bot has def _run_frame(self, executor, limit=False, iteration=0):
""" Run single frame of the bot```
:param executor: The LiveExecutor which can rollback on errors def run(self, inputcode, iterations=None, run_forever=False, frame_limiter=False, verbose=False)
... It looks like there might be a bit of duplication between the logic in run and _run_frame. It could be worth putting some print statements in these places, especially checking _should_run, _dynamic and what iterations is. |
The first case running 3x is strange, but we can probably work it out. If this can be reproduced without the GUI it should be easy(ish) to make a test, if it needs the GUI it would be more tricky. |
Further notes: Bug only occurs when running in windowed mode, so this may be GUI events causing extra drawing. sbot 3.bot
$ sbot -w 3.bot
rgb
hsb
hsb
hsb
hsb
hsb
$ sbot 3.bot -o blah.png
rgb
hsb |
Pinned - we need a way to test running under Gtk headlessly + get some tests around execution to solve this. |
Tests now run under Gtk, so implementing tests for this should be fairly straightforward. |
Trying to write some tests for this + realising current code is a bit insane, so some notes: First question is how to decide if we are an animation. https://plotdevice.io/tut/Animation |
Probably need some idea of animation state that lives outside the bot namespace to do this in a sane way. Then the two kinds of bot:
Can be handled sanely. Obviously needs tests :) |
Nodeboxes design of having a "runner" is a nice way of encapsulating this logic, wish I'd looked there ages ago. |
I'm going to be annoying and add this to the release blockers for 1.4.0, reason being that I have the testing framework setup for this partially done on my computer. Some lifetime fixes are outstanding when running in the GUI:
|
Goodness me! This bug has triggered a lot of changes - some pretty large - and we are still not all the way there. Here is a little writeup: This bug occurs in the main loop, which sits at the heart of Shoebot. When this bug was reported our test framework was pretty non-existent, so changing the main loop would have been very risky. We added a new test framework, that was able to run bots in headless and windowed mode, we included useful features like being able to verify visual output. This helped us find many other bugs, implement many other features (with tests) and make our CI much more useful. Once the test suite matured replacing the main loop was relatively painless. This made the code easier to read and Shoebot was able to run code in the global scope once as opposed to 3x. As is often the case, this revealed a new bug or two: In Shoebot you can change the size of the window with the Shoebot renders scripts at the window size. Unfortunately, if the user calls Currently, Shoebot's graphics backend can only output each frame once. Future work: Rewriting our main loop to better separate concerns (running scripts, handling events) made it easier to understand this bug. Once that work is complete Shoebot, will be free of a persistent bug and, with any luck: a little more maintainable. |
This is evident with print output -- code is executed 3 times and variables don't reset between runs. Serious stuff :-/
The text was updated successfully, but these errors were encountered: