lordmauve / lordmauve/pgzero

Crash in convert_alpha() when using IDE mode

Open
#264 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
611
Forks
211
PR merge metrics
No merged PRs in 30d

Description

I had to reinstall my system last night so ended up reinstalling pygame zero again. I'm on Arch Linux. With all the incompatibilities with python and pygame and old code i am running the dev branch of pygame zero. with the standard archlinux SDL, pygame, and python packages. pygame zero is the only one i have to manually install. Also i have to disable it's dependencies or it tries to pull uncompatable pygame packages in to my system. This has been a headache since we first started using pygame zero. Not sure if it's a major python problem or who is at fault. However it has been working for me as long as i use all standard packages and pip the dev version of pygame zero without letting it install pygame. But today it's broken after fresh install. I found that setting the ICON variable or creating an Actor causes a crash. However blitting an image like a background in the draw function doesn't.

import pgzrun

WIDTH = 800
HEIGHT = 600
TITLE = "Astroids!"
ICON = "icon"

pgzrun.go()

or loading an Actor.

import pgzrun
from pgzero.builtins import screen, Actor

WIDTH = 800
HEIGHT = 600

ship = Actor("ship")


def draw():
screen.blit("backdrop", (0, 0))
ship.draw()


def update():
pass


pgzrun.go()

The above code will cause the crash.

Traceback (most recent call last):
File "/home/jeremiah/Desktop/Tutorials/PyGame-Zero/04-Window-Icon.py", line 8, in
pgzrun.go()
File "/usr/lib/python3.9/site-packages/pgzrun.py", line 30, in go
run_mod(mod)
File "/usr/lib/python3.9/site-packages/pgzero/runner.py", line 181, in run_mod
PGZeroGame(mod, **kwargs).run()
File "/usr/lib/python3.9/site-packages/pgzero/game.py", line 236, in run
self.mainloop()
File "/usr/lib/python3.9/site-packages/pgzero/game.py", line 294, in mainloop
self.reinit_screen()
File "/usr/lib/python3.9/site-packages/pgzero/game.py", line 80, in reinit_screen
self.show_icon()
File "/usr/lib/python3.9/site-packages/pgzero/game.py", line 117, in show_icon
pygame.display.set_icon(pgzero.loaders.images.load(icon))
File "/usr/lib/python3.9/site-packages/pgzero/loaders.py", line 140, in load
res = self._cache[key] = self._load(p, *args, **kwargs)
File "/usr/lib/python3.9/site-packages/pgzero/loaders.py", line 179, in _load
return pygame.image.load(path).convert_alpha()
pygame.error: No video mode has been set

The equivalent pygame code seems to work just fine.

import pygame

pygame.init()

WIDTH = 800
HEIGHT = 600
TITLE = "Astroids!"
ICON = "images/icon.png"
FPS = 60

running = True

screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption(TITLE)
pygame.display.set_icon(pygame.image.load(ICON).convert_alpha())


def update_input():
global running
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False


while running:
update_input()
pygame.time.Clock().tick(FPS)

pygame.quit()

This issue just started today but i haven't update pygame zero in maybe month or more. The rest of the system is updated daily.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the ICON and Actor examples, then inspect pgzero/game.py around reinit_screen() and show_icon(), followed by pgzero/loaders.py where convert_alpha() is called. Compare the initialization order with the equivalent Pygame example. Done means both reported pygame Zero examples run without the No video mode has been set crash on the stated Arch Linux setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.