Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix _get_pressed() returning list of booleans #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vaibhav-sangwan
Copy link
Contributor

The changes commited in e4d3122 converted the type of self.__keystate from bool array into dict(int: bool). However, _get_pressed() still returns a list of 134 booleans. Checking key presses for a key such as pygame.K_RIGHT(1073741903) would go past the size of the list resulting in an IndexError.

  • return self.__keystate dict from _get_pressed() instead of it's values.

Solves the issue encountered in sugarlabs/ball-and-brick-activity#24 (comment).

@quozl, @walterbender, @chimosky please review.

@quozl
Copy link
Contributor

quozl commented Apr 14, 2024 via email

@chimosky
Copy link
Member

What activity did you notice this in? Any steps to reproduce?

@vaibhav-sangwan
Copy link
Contributor Author

The issue was originally encountered in BallAndBrick activity. My testing environment consists of sugar 0.118 on Ubuntu 22.04 (Pygame 2.5.2, Python 3.10.12).
To reproduce the issue, you can test af89d7c. On the landing screen, press C to hop into the game, and then pressing the right and left arrow keys won't trigger any movement. The following error is shown in logs -

Traceback (most recent call last):
 File "/home/vishu/Activities/ball-and-brick-activity/game.py", line 601, in run
   settings()
 File "/home/vishu/Activities/ball-and-brick-activity/game.py", line 471, in settings
   gameLoop()
 File "/home/vishu/Activities/ball-and-brick-activity/game.py", line 512, in gameLoop
   check_input()
 File "/home/vishu/Activities/ball-and-brick-activity/game.py", line 209, in check_input
   if keys[pygame.K_LEFT]:
IndexError: list index out of range

@chimosky
Copy link
Member

I tested the changes you made and it works just fine without this change to sugargame.

@vaibhav-sangwan
Copy link
Contributor Author

vaibhav-sangwan commented Apr 24, 2024

Did you test all the commits? The changes made in b03de8c replaced the usage of pygame.key.get_pressed() and thus the BallAndBrick activity would work fine without any changes to sugargame.
However, while testing the activity after commit 9eb67d3, the activity froze on welcome page and in the logs, the above mentioned error was shown.

_get_pressed() returns a list of 134 booleans. Checking key presses for a key
such as pygame.K_RIGHT(1073741903) would go past the 134 element list resulting
in an IndexError.

* return self.__keystate dict from _get_pressed() instead of it's values.
@vaibhav-sangwan
Copy link
Contributor Author

I wanted to change the commit message only but mistakenly pushed some unwanted changes. So had to force push twice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants