Issue #55 resolved

str/bytes issue in gamecontroller.py

andy_s
created an issue

Loading game controller mappings from a file triggers a str/bytes error on Python 3:

sdl.SDL_GameControllerAddMappingsFromFile(b"gamecontrollerdb.txt")

results in

Traceback (most recent call last):
  File "D:\Code\pysdl2_tests\2_gamepad.py", line 80, in <module>
    main()
  File "D:\Code\pysdl2_tests\2_gamepad.py", line 49, in main
    sdl.SDL_GameControllerAddMappingsFromFile(b"gamecontrollerdb.txt")
  File "./PySDL2\sdl2\gamecontroller.py", line 107, in <lambda>
    SDL_GameControllerAddMappingsFromFile = lambda fname: SDL_GameControllerAddMappingsFromRW(SDL_RWFromFile(fname, "rb"), 1)
ctypes.ArgumentError: argument 2: <class 'TypeError'>: wrong type

To fix it, the "rb" argument to SDL_RWFromFile in gamecontroller.py, line 107, must be passed as a bytes object, i.e. using b"rb" or byteify("rb")

Comments (1)

  1. Log in to comment