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

set_handler bug and refactoring suggestion #763

Open
GoogleCodeExporter opened this issue Apr 6, 2015 · 0 comments
Open

set_handler bug and refactoring suggestion #763

GoogleCodeExporter opened this issue Apr 6, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

There is bug in set_handler. E.g. pyglet crash with simple code below:
import pyglet

window = pyglet.window.Window()
def on_draw():
    pass

window.push_handlers(on_draw)
window.pop_handlers()
@window.event
def on_resize(w, h):
    pass
pyglet.app.run()

The reason is that in pop_handlers del self._event_stack[0] is used to delete 
events on top of stack and in set_handler inserting events is doing by  
self._event_stack[0][name] = handler without checking the length of 
event_stack. Fix is as simple as adding check, but personally I think it would 
be better to rewrite whole stack code.

First of all I don't understand why empty stack is defined as tuple and changed 
to list if event are to be added. It only complicates the code. 
Pushing new element on stack in done by
self._event_stack.insert(0, {})
self.set_handlers(*args, **kwargs)
while I think using append list method would be better (and probably faster)

pop_handlers:
now: del self._event_stack[0]
new: self._event_stack.pop()

I hope you get general idea. If you agree with above suggestions I can refactor 
code and provide patch. 

Original issue reported on code.google.com by fen...@gmail.com on 7 Sep 2014 at 7:58

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant