libtcod / python-tcod

A high-performance Python port of libtcod. Includes the libtcodpy module for backwards compatibility with older projects.
BSD 2-Clause "Simplified" License
410 stars 36 forks source link

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb4 in position 0: invalid start byte #24

Closed Tairesh closed 7 years ago

Tairesh commented 7 years ago

Hello. I trying to run examples/tutorial/2-Movement.py with no changes and get a error when I pressed numpad buttons.

24 bits font. key color : 0 0 0 Traceback (most recent call last): File "C:\Users\ilya_gorohov\Documents\tdltest\main.py", line 60, in <module> for event in tdl.event.get(): # Iterate over recent events. File "C:\Users\ilya_gorohov\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tdl\event.py", line 384, in get _processEvents() File "C:\Users\ilya_gorohov\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tdl\event.py", line 365, in _processEvents libkey.ralt, libkey.rctrl, libkey.shift)) File "C:\Users\ilya_gorohov\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tdl\event.py", line 115, in __init__ char = char if isinstance(char, str) else char.decode() UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc4 in position 0: unexpected end of data

Windows 10, Python 3.6, tdl 2.0.1

HexDecimal commented 7 years ago

Keypad percent, I don't have that on my keyboard, and it seems to be missing in libtcod itself.

The best I can do is have tdl ignore keys that are undefined by libtcod.

HexDecimal commented 7 years ago

New release v3.0.0 shouldn't crash, but the event attributes will be mostly blank.

Tairesh commented 7 years ago

Now. in 3.0.0 I get a new error when I press a numpad or letter buttons without left alt:

Traceback (most recent call last): File "C:\Users\ilya_gorohov\Documents\tdltest\main.py", line 65, in for event in tdl.event.get(): # Iterate over recent events. File "C:\Users\ilya_gorohov\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tdl\event.py", line 413, in get _processEvents() File "C:\Users\ilya_gorohov\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tdl\event.py", line 387, in _processEvents libkey.lalt, ValueError: got a _Bool of value 100, expected 0 or 1

HexDecimal commented 7 years ago

I'm able to repeat the _Bool issue on Python 3.6.1 (32-bit). That issue doesn't show up in a 64-bit build.

libtcod doesn't seem to define the modifier keys on SDL text events.

Released v3.0.1, which manually zeroes out those values as a temporary fix.

Tairesh commented 7 years ago

Now event.get() is nice working for me, thanks