[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] This program breaks on my Linux
Hey, I bet you forgot about me! :)
I finally upgraded to Ubuntu 14.04. Alas, this problem did not go away. Since the last message:
- I learned it doesn't matter if FPS is artificially capped; but faster FPS seems to make the problem occur more reliably. This rules out throttled vs. un-throttled.
- I learned it doesn't matter if the window is small or big; but smaller gets faster FPS seems to make the problem occur more reliably. This may rule out total blit calls and total pixels per frame.
- I learned it doesn't matter if the game uses the local display or remote over a SSH tunnel. I think this rules out video drivers.
- incorporated the feedback from DR0ID, to put the exit calls outside the main loop.
- incorporated the feedback from Sam, to use print statements to show exit progress.
The issue seems to be in the shutdown/cleanup code of pygame. Yet, as I indicated before the strange behavior (sudden permanent boost in FPS) is observed well before program exit. Although this is harder to spot in Ubuntu 14.04 because I'm getting near max FPS from the beginning.
The updated program is attached.
import sys
import time
import pygame
from pygame.locals import *
pygame.init()
resolution = 1024, 768
image_size = 200
# these two lines run better over ssh -X ...
#resolution = 196, 16
#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(1)
pygame.display.get_init()
progress(2)
pygame.display.get_surface()
progress(3)
screen.unlock()
progress(4)
pygame.display.set_mode((16, 64))
progress(5)
pygame.display.flip()
progress(6)
pygame.quit()
progress(7)
sys.exit()
progress(8)