pygame / solarwolf

☀️🐺 SolarWolf is an action/arcade game written in Python. It is free and open source, created with the Pygame game development library.
64 stars 27 forks source link

AttributeError (event has no attribute state) in Python 3.10.6 #13

Closed kumoshk closed 3 months ago

kumoshk commented 2 years ago

I installed Solarwolf with aptitude or apt on Xubuntu 22.04.1 (running the Cinnamon desktop), and I tried the same with the version on Github here, and I got the following error for line 78 in main.py:

AttributeError: 'Event' object has no attribute 'state'

I also figured out how to fix it:

Change

            elif event.type == pygame.ACTIVEEVENT:
                if event.state == 4 and event.gain:
                    #uniconified, lets try to kick the screen
                    pygame.display.update()
                elif event.state == 2:
                    if hasattr(game.handler, 'gotfocus'):
                        if event.gain:
                            game.handler.gotfocus()
                        else:
                            game.handler.lostfocus()
                continue

to

            elif event.type == pygame.ACTIVEEVENT:
                if "state" in event.__dict__:
                    if event.state == 4 and event.gain:
                        #uniconified, lets try to kick the screen
                        pygame.display.update()
                    elif event.state == 2:
                        if hasattr(game.handler, 'gotfocus'):
                            if event.gain:
                                game.handler.gotfocus()
                            else:
                                game.handler.lostfocus()
                continue

Some of the powerups don't look like I think they're supposed to, though. I'm not sure if that's related to this.

kumoshk commented 2 years ago

Anyway, if the attribute doesn't exist, I'm guessing it's not 4 or 2! :)

illume commented 11 months ago

I can't see this problem with the main branch and pygame 2.5.2. So I guess it's fixed now.

Maybe it's an issue with an older pygame version.

(It's been a long time since the issue is reported. But if it's still a problem I'd like to know more info about your versions).

kumoshk commented 11 months ago

I can't see this problem with the main branch and pygame 2.5.2. So I guess it's fixed now.

Maybe it's an issue with an older pygame version.

(It's been a long time since the issue is reported. But if it's still a problem I'd like to know more info about your versions).

Here's what I'm using:

Xubuntu 22.04.2 LTS (64-bit) (I guess my OS has been updated a bit since I submited it.) Solarwolf version 1.5+dfsg1-5 python3-pygame version 2.1.2+dfsg-3

These are the versions installed with the package manager.

I haven't tried a newer version as of yet.

Here are my Python versions: python3 version 3.10.6-1~22.04 python2 version 2.7.18-3 (I'm guessing it's using Python 3.x, but I'm telling you this information anyway.)

lcerf commented 7 months ago

Same problem here, on Trisquel 11, which is based on Ubuntu 22.04 (hence essentially the same versions as kumoshk reported), if SolarWolf runs fullscreen. No problem in a window display. The (in)existence of ~/.solarwolf makes no difference.

Since my TV gives the resolution, I can see that, in full screen (which turns all black), SolarWolf first changes the resolution for 800x600p@60Hz, then goes back to 1920x1080p@60Hz (the resolution I use), then 800x600p@60Hz again and 1920x1080p@60Hz again, back on my desktop and showing me an error box explaining that 'Event' object has no attribute 'state'.

Avoiding the execution of the line testing event.state, for instance with kumoshk's additional test, the screen resolution goes 800x600p@60Hz, then 1920x1080p@60Hz, then 800x600p@60Hz again, SolarWolf's menu appear and the game runs fine, but the 4:3 display is horizontally stretched out to fill the entire 16:9 TV screen.

The same error occurs on my laptop screen, also using the resolution1920x1080@60Hz, with the fullscreen display, unless I avoid the execution of the line testing event.state. If I do avoid its execution, SolarWolf not only runs fine but the display is not stretched out, thanks to black strips (or whatever it is called) on the left and on the right of the screen.

Here is a video of the problem: https://dcc.ufmg.br/~lcerf/2024-02-28-15-48-22.webm (at the end of the OBS record, the video appears black, but the game was actually running).

illume commented 3 months ago

This issue was fixed in the main branch, and is fixed in solarwolf 1.6.0.

When distros update it should be fixed. (Or you can download the source from github, or install via pip.)