[pygame] BUG: Crash due to encoding when reposting events

28 views
Skip to first unread message

Son-Goku

unread,
Dec 11, 2020, 7:57:31 AM12/11/20
to pygame...@seul.org
Hi,

I believe to have found a bug that crashes pygame due to an encoding problem.

My goal was to react to a specific event inside a (waiting) function while leaving the event queue untouched, so that the outer (main) function behaves as if I would have never read any events from the queue. I therefore reposted all events I consumed (via pygame.event.get()). This worked until I was pressing keys during execution of this (waiting) function.

Minimal working example:

> import pygame, time
> pygame.init()
> pygame.display.set_mode()
> time.sleep(1)
> for event in pygame.event.get():
> print('reposting', event)
> pygame.event.post(event)
>
> events = pygame.event.get()

I use "time.sleep(1)" here just to have enough time to press a key. When I do (I pressed the space key), I get the following output:

> pygame 2.0.0 (SDL 2.0.12, python 3.9.0)
> Hello from the pygame community. https://www.pygame.org/contribute.html
> reposting <Event(4352-AudioDeviceAdded {'which': 0, 'iscapture': 0})>
> reposting <Event(4352-AudioDeviceAdded {'which': 1, 'iscapture': 0})>
> reposting <Event(4352-AudioDeviceAdded {'which': 0, 'iscapture': 1})>
> reposting <Event(4352-AudioDeviceAdded {'which': 1, 'iscapture': 1})>
> reposting <Event(512-WindowEvent {'event': 1, 'window': None})>
> reposting <Event(32768-ActiveEvent {'gain': 1, 'state': 1, 'window': None})>
> reposting <Event(512-WindowEvent {'event': 12, 'window': None})>
> reposting <Event(770-TextEditing {'text': '', 'start': 0, 'length': 0, 'window': None})>
> reposting <Event(32768-ActiveEvent {'gain': 1, 'state': 0, 'window': None})>
> reposting <Event(512-WindowEvent {'event': 10, 'window': None})>
> reposting <Event(1024-MouseMotion {'pos': (945, 226), 'rel': (0, 0), 'buttons': (0, 0, 0), 'window': None})>
> reposting <Event(32768-ActiveEvent {'gain': 0, 'state': 0, 'window': None})>
> reposting <Event(512-WindowEvent {'event': 11, 'window': None})>
> reposting <Event(32768-ActiveEvent {'gain': 1, 'state': 0, 'window': None})>
> reposting <Event(512-WindowEvent {'event': 10, 'window': None})>
> reposting <Event(1024-MouseMotion {'pos': (945, 226), 'rel': (0, 0), 'buttons': (0, 0, 0), 'window': None})>
> reposting <Event(32770-VideoExpose {})>
> reposting <Event(512-WindowEvent {'event': 3, 'window': None})>
> reposting <Event(768-KeyDown {'unicode': ' ', 'key': 32, 'mod': 4096, 'scancode': 44, 'window': None})>
> reposting <Event(771-TextInput {'text': ' ', 'window': None})>
> reposting <Event(769-KeyUp {'key': 32, 'mod': 4096, 'scancode': 44, 'window': None})>
> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xde in position 3: invalid continuation byte
>
> The above exception was the direct cause of the following exception:
>
> Traceback (most recent call last):
> File "bug.py", line 9, in <module>
> events = pygame.event.get()
> SystemError: <built-in function get> returned a result with an error set

It is the second call to "pygame.event.get()" that results in the crash, and it does so only if I press a key during execution (otherwise, no exception occurs). I use UTF-8 as encoding for my source file. Adding an encoding comment at the beginning of the file does not make a difference.

Best wishes
goku

Son-Goku

unread,
Dec 11, 2020, 8:02:23 AM12/11/20
to pygame...@seul.org
Reply all
Reply to author
Forward
0 new messages