Pygame window not responding after a few seconds

Fred picture Fred · Nov 23, 2013 · Viewed 20.1k times · Source

This simple piece of code crashes (the window is not responding) after a few seconds (around 5).

import pygame
from pygame.locals import *

pygame.init()
screen = pygame.display.set_mode((640, 480), 0, 24)
#clock = pygame.time.Clock()

#font = pygame.font.Font(None, 32)

cycles = 0
while True:
    screen.fill(0)
#    text = font.render('Cycles : %d' % cycles, True, (255, 255, 255))
#    screen.blit(text, (100, 100))

    cycles += 1

    pygame.display.update()

If I uncomment the commented lines, I can clearly see the program going out of control when displaying values between 47 and 50.

I use python 2.7 and pygame 1.9.2, Windows 8 (64 bits) and Eclipse + PyDev.

Answer

user2746752 picture user2746752 · Nov 23, 2013

Call pygame.event.get() at the beginning of the while loop.