Sticky exception when thrown inside Scene.controller_changed
robnee last edited by robnee
I have a problem with Pythonista where, if I have a bug in my Scene.controller_changed function even after the bug is fixed the old exception will still be thrown every time controller_changed is called. This can be reset by force-quitting Pythonista. It's annoying because it makes you think your bug fixes aren't working.
I'm happy to file an Issue for this but I thought it might be a good idea to ask if someone else can reproduce this. Notice the code below has two undefined name bugs. If you run this code you will get an exception on screen touch and pressing 'X' on a MFI controllers. Do this. Then fix both bugs by replacing bug with dog. Now when you run and tap the screen you should get a little 'woof' in the lower left-hand corner of the screen. However, when you press 'X' on a controller the old exception will still be thrown.
Can someone with a MFI controller please try this and see if you can reproduce this?
'''This is trying to demonsrate a problem in Pythonista where an exception thrown inside controller_changed becomes "sticky" and will be rethrown even after the problem code is fixed. ''' import scene dog = 'woof' class MyScene (scene.Scene): def touch_began(self, touch): print(bug) def controller_changed(self, id, key, value): if key == 'button_x' and value: print(bug) if __name__ == '__main__': scene.run(MyScene())
@robnee , you are not quoting bug. There is no var bug
class MyScene (scene.Scene): def touch_began(self, touch): print('bug') def controller_changed(self, id, key, value): if key == 'button_x' and value: print('bug')
robnee last edited by
Yes. I know there is a bug in the program. It's specifically designed to throw uncaught exceptions. Once an exception is thrown inside the controller_changed function however, it is remembered. Even after you fix the bug, any way you like perhaps by quoting the word 'bug', the exception will still be thrown with a reference to the old argument to print. You must force-quit Pythonista in order to reset the interpreter to make the code run again. The same thing does not seem to happen with touch_began. If you run, get the exception in touch_began, fix the bug, rerun, and tap the exception will not reoccur. Of course, this is the expected and desired behavior. It's something peculiar to controller_changed that seems to be the problem. Please try and see if this same thing happens to you.
@robnee , ok I sort oh see. I will stand back and let someone who knows what they are talking about help you. I do nothing with scene, just looked at it thinking maybe I could help.
robnee last edited by
No problem! I just felt like maybe I did a bad job of explaining my question so I wanted to restate. Thanks for offering to help. It why were all here :)
I should have realised that
def controller_changed(self, id, key, value) was a callback of some sorts. I havnt come across it before. Just looked it up. It's a game controller event, I had no hope in hell in helping 😁😁😁