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

[pygame] This program breaks on my Linux



Howdy,

Hoping some folks can try this out. I have no idea why it is happening. Not even a theory. Could be anything from drivers to the Python or SDL build. Here's the scoop...

The environment:
- i5 desktop computer (not a virtual machine)
- Ubuntu 13.04 x86_64
- Python 2.7
- pygame 1.9.1

The program blits a checkerboard background using only two images, and pans the images diagonally back and forth forever. The clock is not throttled.

The problem usually occurs anywhere from 3 to 120 seconds after start. During the normal behavior, I'm getting about 320 fps with occasional instantaneous spikes to 500+ fps. (I don't know if the spikes are normal. They do cause visible glitches.)

During the problem behavior the fps spikes permanently to about 580 fps and stays pegged. Who would complain about sustained 580 fps, ay? :) Well, then when pygame quits, the program freezes and the window remains open with the checker pattern intact. SIGTERM (15) does not kill the program. SIGKILL (9) does.

This issue does not happen in Windows 7. And it does not happen if I throttle the clock enough to lower the max fps.

I attached the small program. I'm curious if anyone can run it and reproduce the problem. I plan on upgrading Ubuntu soon, when I am ready to risk it: maybe the problem will go away. I'll post the outcome--but I've been too busy to risk the upgrade, so don't hold yer breath. =)

Thanks.

Gumm
import sys

import pygame
from pygame.locals import *

pygame.init()
resolution = 1024, 768
image_size = 200
screen = pygame.display.set_mode(resolution)
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
while True:
    
    dt = clock.tick(max_fps)
    
    fps = int(round(clock.get_fps()))
    meter = 'o' * (fps  / 10)
    pygame.display.set_caption('Fps {0} {1}'.format(fps, meter))
    
    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:
                pygame.quit()
                quit()
    
    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()