[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] event queue full



On Jun 14, 2004, at 4:40 PM, Sami Hangaslammi wrote:
On Mon, 14 Jun 2004, Jack Nutting wrote:
     # filter our event queue
     pygame.event.set_allowed([])
     pygame.event.set_allowed([KEYDOWN,KEYUP,QUIT])
I think this might be your problem. The first call doesn't actually do
anything. If you pass a list as parameter, it merely re-allows all listed
events. In order to first set all events as blocked, you must call
pygame.event.set_allowed(None)

(I'm not actually sure if pygame treats an empty list as somehow special,
but I doubt it. And the docs tell you to use None to block events.)
Yup, that did the trick. I apparently misread the docs and figured an empty list would clear the list of allowed events (plus, I was so early in my Python education when I wrote that, I probably didn't know about None). Thanks!

And:

On Jun 14, 2004, at 4:37 PM, Pete Shinners wrote:
Jack Nutting wrote:
    for event in pygame.event.get([KEYDOWN,KEYUP,QUIT]):
I have a hunch this is still your problem somehow. Change the line to this,

for event in pygame.event.get():
That also does the trick!

By getting all events you will really make sure the queue is empties each time you loop through the events. It looked like all the other event types should be disabled anyways.

In hindsight I've found providing a list of event types to pygame.event.get() is fairly dangerous. It only removes the events you are interested, and anything else can get piled up on the queue. SDL's event queue is only 256 elements, which is plenty for one frame but fills up fast if left alone.
So my problem was twofold: I was incorrectly calling pygame.event.set_allowed() with an empty list instead of None to clear it out (so all events were getting passed through) and I was calling pygame.event.get() with a list of event types which made it ignore those unwanted events (thereby leaving them in the queue for future havoc). Fixing either/both of these problems makes the badness go away.

Thanks,

//jack