[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] This program breaks on my Linux



Argh! pygame.mixer.quit() is hanging.

('keydown', 'escape')
Exit progress: begin
Exit progress: pygame.display.get_init()
Exit progress: pygame.display.get_surface()
Exit progress: screen.unlock()
Exit progress: pygame.display.set_mode((16, 64))
Exit progress: pygame.display.flip()
Exit progress: pygame.display.quit()
Exit progress: pygame.mixer.quit()

Gumm


On Wed, Jul 16, 2014 at 2:49 PM, Sam Bull <sam.hacking@xxxxxxxx> wrote:
On mer, 2014-07-16 at 14:36 -0700, B W wrote:
> The issue seems to be in the shutdown/cleanup code of pygame.

The program appears to only use the pygame.display module, so if it is
currently crashing in pygame.exit(), then it may be an idea to try
initialising and exiting individual modules, to see if the problem is in
a single module's shutdown.

So, replace pygame.init() with pygame.display.init(), and pygame.quit()
with pygame.display.quit(). If the crash disappears, then start adding
additional module init's and quit's and see if you can narrow the crash
into a single module's quit() function. Other modules include
pygame.mixer and pygame.scrap.

import sys
import time

import pygame
from pygame.locals import *

pygame.display.init()
pygame.mixer.init()
#pygame.scrap.init()  #pygame.error: no display mode is set
resolution = 1024, 768
image_size = 200
# these two lines run better over ssh -X ...
resolution = 196, 32
image_size = 8
screen = pygame.display.set_mode(resolution, DOUBLEBUF)
screen_rect = screen.get_rect()
scroll_rect = Rect(screen_rect)
scroll_rect.width *= 5
scroll_rect.height *= 5
clock = pygame.time.Clock()
images = (
    pygame.Surface((image_size, image_size)),
    pygame.Surface((image_size, image_size)),
)
images[0].fill(Color('slategray2'))
images[1].fill(Color('slategray3'))
image_rect = images[0].get_rect()
bg_color = Color('black')
dx = -1
dy = -1
max_fps = 0
high_fps = 0
running = True
while running:
    
    dt = clock.tick(max_fps)
    
    fps = int(round(clock.get_fps()))
    if fps > high_fps:
        high_fps = fps
    meter = 'o' * (fps  / 20)
    pygame.display.set_caption('Fps {2}/{0} {1}'.format(fps, meter, high_fps))
    
    scroll_rect.move_ip(dx, dy)
    if not scroll_rect.contains(screen_rect):
        dx = -dx
        dy = -dy
    
    screen.fill(bg_color)
    line_num = 0
    for y in xrange(scroll_rect.y, scroll_rect.bottom, image_size):
        checker = 0 if line_num % 2 else 1
        line_num += 1
        for x in xrange(scroll_rect.x, scroll_rect.right, image_size):
            image_rect.x = x
            image_rect.y = y
            if screen_rect.colliderect(image_rect):
                screen.blit(images[checker], image_rect)
            checker = 0 if checker == 1 else 1
    pygame.display.flip()

    for e in pygame.event.get():
        if e.type == KEYDOWN:
            print('keydown',pygame.key.name(e.key))
            sys.stdout.flush()
            if e.key == K_ESCAPE:
                running = False


def progress(n):
    print('Exit progress: {0}'.format(n))
    sys.stdout.flush()

progress('begin')

progress('pygame.display.get_init()')
pygame.display.get_init()

progress('pygame.display.get_surface()')
pygame.display.get_surface()

progress('screen.unlock()')
screen.unlock()

progress('pygame.display.set_mode((16, 64))')
pygame.display.set_mode((16, 64))

progress('pygame.display.flip()')
pygame.display.flip()

progress('pygame.display.quit()')
pygame.display.quit()

progress('pygame.mixer.quit()')
pygame.mixer.quit()

progress('pygame.scrap.quit()')
pygame.scrap.quit()

progress('sys.exit()')
sys.exit()

progress('done')