WinterLicht / Chaos-Projectile

Run ‘n’ Gun meets RPG
60 stars 17 forks source link

'pygame.error: Invalid joystick hat' at first run and crash #10

Open Deevad opened 8 years ago

Deevad commented 8 years ago

2016-03-08_screenshot_001

Hi, As a newbie, I'm doing my first local install, cloning the game at commit 714d34cab32cddd74bd1b144d4bd747bfe20b4fc on a LinuxMint 17.3 Cinnamon 64bit (ubuntu 14.04 based, rather old library) the viewport of the game launch, blink then crash after a little half-second.

Python is 2.7.6 when I do python -V in a console. Here is the full log, text version:

deevad@workstation ~ $ sudo apt-get install python-pygame python-pip
[sudo] password for deevad: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-pygame is already the newest version.
python-pip is already the newest version.
The following packages were automatically installed and are no longer required:
  libaudcore1 libbinio1ldbl liblensfun-data liblensfun0 libmowgli2 libpano13-2
  libzthread-2.3-2 linux-image-3.16.0-38-generic
  linux-image-extra-3.16.0-38-generic
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 23 not upgraded.
deevad@workstation ~ $ sudo pip install pytmx 'pyscroll<2.16.2' --force-reinstall
Downloading/unpacking pytmx
  Downloading PyTMX-3.20.14.zip
  Running setup.py (path:/tmp/pip_build_root/pytmx/setup.py) egg_info for package pytmx

Downloading/unpacking pyscroll<2.16.2
  Downloading pyscroll-2.16.1.zip
  Running setup.py (path:/tmp/pip_build_root/pyscroll/setup.py) egg_info for package pyscroll

Requirement already satisfied (use --upgrade to upgrade): six in /usr/lib/python2.7/dist-packages (from pytmx)
Requirement already satisfied (use --upgrade to upgrade): pygame in /usr/lib/python2.7/dist-packages (from pyscroll<2.16.2)
Installing collected packages: pytmx, pyscroll
  Running setup.py install for pytmx

  Running setup.py install for pyscroll

Successfully installed pytmx pyscroll
Cleaning up...
deevad@workstation ~ $ cd ~/Sources
deevad@workstation ~/Sources $ git clone https://github.com/WinterLicht/Chaos-Projectile.git
Cloning into 'Chaos-Projectile'...
remote: Counting objects: 1416, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 1416 (delta 0), reused 0 (delta 0), pack-reused 1409
Receiving objects: 100% (1416/1416), 40.05 MiB | 1.58 MiB/s, done.
Resolving deltas: 100% (918/918), done.
Checking connectivity... done.
deevad@workstation ~/Sources $ cd Chaos-Projectile/
deevad@workstation ~/Sources/Chaos-Projectile $ ls
doc  README.md  src
deevad@workstation ~/Sources/Chaos-Projectile $ cd src/
deevad@workstation ~/Sources/Chaos-Projectile/src $ python game.py
SDL_JoystickGetAxis value:-32767:
SDL_JoystickGetAxis value:-32767:
Traceback (most recent call last):
  File "game.py", line 76, in <module>
    spinner.run()
  File "game.py", line 42, in run
    self.event_manager.post(event)
  File "/home/deevad/Sources/Chaos-Projectile/src/events.py", line 408, in post
    listener.notify(event)
  File "/home/deevad/Sources/Chaos-Projectile/src/controller.py", line 76, in notify
    if self.joystick.get_hat(0):
pygame.error: Invalid joystick hat
deevad@workstation ~/Sources/Chaos-Projectile/src $

I hope this is not my operating-system. I'm available to enter more command line in terminal if you need more information about my library versions. Thank you for your time.

Funatiker commented 8 years ago

There might be a problem about some pseudo-joysticks as pointed out in #5.

Can you try this patch? https://github.com/Funatiker/Chaos-Projectile/commit/7bc2dc5e6bb6beca5c04035480e22c804a04aae8

WinterLicht commented 8 years ago

Patch merged. @Deevad please pull ChaosProjectile and try to run the game again. The game was tested with a Sony PS1 Controller. I guess it will not work with a XBox game pad. (Its axis are indexed different in pygame). The game is playable with keyboard (WAD-keys) and mouse.

Sorry for late returns, somehow I do not get E-Mail notifications for every new issues & every message.

Deevad commented 8 years ago

Thank you @Funatiker and @WinterLicht ( got your email, I'll reply asap ;-) ). No problem for reply time, it was fast and I have the month :-) I updated, then I tried again, but I'm blocked with the same time of issue:

deevad@workstation ~/Sources/Chaos-Projectile $ git pull
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 7 (delta 3), reused 3 (delta 3), pack-reused 1
Unpacking objects: 100% (7/7), done.
From https://github.com/WinterLicht/Chaos-Projectile
   ec0325c..8beccef  master     -> origin/master
Updating ec0325c..8beccef
Fast-forward
 src/controller.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
deevad@workstation ~/Sources/Chaos-Projectile $ cd src
deevad@workstation ~/Sources/Chaos-Projectile/src $ python game.py
SDL_JoystickGetAxis value:-32767:
SDL_JoystickGetAxis value:-32767:
Traceback (most recent call last):
  File "game.py", line 76, in <module>
    spinner.run()
  File "game.py", line 42, in run
    self.event_manager.post(event)
  File "/home/deevad/Sources/Chaos-Projectile/src/events.py", line 408, in post
    listener.notify(event)
  File "/home/deevad/Sources/Chaos-Projectile/src/controller.py", line 76, in notify
    if self.joystick.get_hat(0):
pygame.error: Invalid joystick hat
deevad@workstation ~/Sources/Chaos-Projectile/src $ 
Funatiker commented 8 years ago

@Deevad oops. My bad. Sorry. My patch only included checking whether there are enough axes but not whether there are enough hats.

Can you try whether this patch fixes it for your hardware?

controllerpatch.diff.txt

Deevad commented 8 years ago

Thank you @Funatiker , your patch is working here, now I need to find a Joystick to move the character. :-) 2016-03-08_screenshot_003

Funatiker commented 8 years ago

@Deevad Glad to hear that. My code does no magic. It just ignores controllers without hats. Maybe we should think about adding support for the controllers you have. There is another problem: We assume the controller to have a specific ID. If PyGame knows several joysticks (i.e several controller or controller-like devices plugged in) and the wrong one has the assumed ID, the game will believe that there is no compatible controller.

Deevad commented 8 years ago

It's fun, because I had all this issues with no joystick plugged. Maybe it's my graphic tablet, or my mouse, or my keyboard...

deevad@workstation ~ $ lsusb 
Bus 002 Device 007: ID 17a0:0310 Samson Technologies Corp. Meteor condenser microphone
Bus 002 Device 004: ID 046d:081d Logitech, Inc. HD Webcam C510
Bus 002 Device 010: ID 04a9:173e Canon, Inc. MP560
Bus 002 Device 008: ID 1532:0016 Razer USA, Ltd DeathAdder Mouse
Bus 002 Device 009: ID 056a:00b2 Wacom Co., Ltd Intuos3 9x12
Bus 002 Device 006: ID 1a40:0201 Terminus Technology Inc. FE 2.1 7-port Hub
Bus 002 Device 005: ID 0603:00f2 Novatek Microelectronics Corp. 
Bus 002 Device 003: ID 1a40:0201 Terminus Technology Inc. FE 2.1 7-port Hub
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0bc2:5021 Seagate RSS LLC FreeAgent GoFlex USB 2.0
Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Funatiker commented 8 years ago

@Deevad That's exactly the point. Some devices are joysticks in PyGame's world although they don't look like joysticks to human beings.

I guess it's your graphic tablet. But maybe you want to run the example code on pygame.joystick and enlighten us?

http://www.pygame.org/docs/ref/joystick.html

Deevad commented 8 years ago

I'm a total noob with Python, I tried to copy the two lines proposed on the page you linked inside a joytest.py file, give it execution right, and run it, here is the result:

deevad@workstation ~ $ nano joytest.py
deevad@workstation ~ $ chmod +x joytest.py 
deevad@workstation ~ $ python joytest.py 
Traceback (most recent call last):
  File "joytest.py", line 1, in <module>
    pygame.joystick.init()
NameError: name 'pygame' is not defined
deevad@workstation ~ $ 
Funatiker commented 8 years ago

Looks like you haven't installed PyGame. How are you able to run the game without PyGame?! o.0

Deevad commented 8 years ago

I have it installed, but I have a mess into this system, it's half python2 and python3 mixed together. I'll try to tweak later this week about it.

Funatiker commented 8 years ago

@Deevad besides running it with python (which is 2.7.3 on your system), have you tried running it with python2 and python3?

WinterLicht commented 8 years ago

The Joystick-Test was started with python 2.7.6 (as stated above it is the output of "python -V") I have the same version. Pygame is installed. Otherwise ChaosProjectile couldn't start with a "python game.py". Also PyTMX and pyscroll are installed correctly.

"name 'pygame' is not defined" may come up from missing "import pygame" at the beginning of the joytest.py!

Btw. SDL_JoystickGetAxis shows (almost) the lowest number for signed integer (16 bit) -32767 (lower is only -32768)

Please consider my comment above, the game was only tested with a Sony controller and it is playable with keyboard&mouse.

Funatiker commented 8 years ago

@WinterLicht You are totally right about the missing import pygame. I better upload my version of the file.

About the irritating values of the axes: The reason might be that controller.py always assumes pygame.joystick.Joystick(0) to be the right controller although this might just be a graphic tablet and not the actual computer. It is plausible that graphic tablets return 0x0…01 or similar when asked for an axis. So we better wait for the results of the debug code. About Sony compatibility: I think we even have a bug for Sony controllers if the controller isn't magically assigned at pygame.joystick.Joystick(0). Let's better wait for results about that.

The biggest problem is that keyboard and mouse input are disabled when the game believes to have a joystick available.

@Deevad Download pygametest.py.txt and run it with Python. Does that help? There is also a work-around that I used with an incompatible controller: AntiMicro helps you to map arbitrary Joystick-events to keyboard-events. The keyboard events for this games are: WASD: moving, arrow keys: shooting, esc: end, f: suicide, mouse movement/click: aiming/shooting

Deevad commented 8 years ago

The script ran! (I just had to change the 'import pygame2' to 'import pygame' on line 2). Thank you @Funatiker for the ready-made script. Here is a screenshot of the output; and you were right: the device pygame analysis as a joystick is my Wacom tablet:

2016-03-09_screenshot_001

Funatiker commented 8 years ago

@Deevad Interesting. Can you take a screenshot with an actual gamepad plugged in?

As I assumed: The non-gamepad-joystick reserves ID 0, controller.py assumes a joystick to be present and disables the keyboard and the game is not playable anymore. Now it would be interesting to see if the same happens with an actual gamepad plugged in.

Deevad commented 8 years ago

@Funatiker With a Sixaxis Ps3 gamepad (USB) connected, it list only the gamepad. I also installed the package jstest-gtk to see if the Ps3Gamepad was auto-installed by LinuxMint, and fun, jstest-gtk list Wacom and the Ps3Gamepad as two devices available for Joystick. Here is the screenshot:

2016-03-09_screenshot_002

Funatiker commented 8 years ago

@Deevad Interesting. PyGame doesn't see the graphic tablet anymore when there is the PS3-USB-Controller and this controller does not have a "hat".

We have two options: Either someone adds compatibility for your controller (and possibly some other controllers … or even a tool to configure controllers) or we enable at least the keyboard when there are only incompatible controllers.

Deevad commented 8 years ago

@Funatiker : Oh I see. The Ps3 gamepad is also something irregular as a joypad for pygame. It looks to be a common issue with pygame joystick module, same for xbox gamepad. ( https://github.com/davide-P/sixAxis/blob/master/sixAxis.py ) I'll try to test with a generic gamepad, if I can find one. About the Wacom, it's a graphic tablet, and imho, maybe all input with keyword 'wacom' should just be blacklisted. Wacom never made a joypad afaik.

Funatiker commented 8 years ago

@Deevad Very interesting. Ignoring Wacom-devices sounds like a good first start. The other option would be seeking for specifically the supported devices.

WinterLicht commented 7 years ago

I've rewritten the whole controller thing. An Intuos3 was not recognized as a joystick on my computer. Default controls should always work now despite "strange" joystick behavior. Let me know if the are still problems.