Pygame crashes after only a few seconds of rendering my code

For some reason, this program crashes after only a second or so of running this. Funnily enough, changing the turnAngle or fps affects how long it lasts before crashing. The error it throws is a ValueError: subsurface rectangle outside of surface area on line 29 / line 9. Any ideas?

import pygame as pg


def rot_center(image, angle):
    orig_rect = image.get_rect()
    rot_image = pg.transform.rotate(image, angle)
    rot_rect = orig_rect.copy()
    rot_rect.center = rot_image.get_rect().center
    rot_image = rot_image.subsurface(rot_rect).copy()
    return rot_image


pg.init()

mainDisplay = pg.display.set_mode([600, 376])

imgSplashBG = pg.image.load('guiAssets/splash/BG.png')
imgSplashFG = pg.image.load('guiAssets/splash/FG.png')
imgSplashRedCircle = pg.image.load('guiAssets/splash/redCircle.png')
imgSplashGreenCircle = pg.image.load('guiAssets/splash/greenCircle.png')

turnAngle = 10

frame = 0
clock = pg.time.Clock()
crashed = False
while not crashed:
    frame += 1
    mainDisplay.blit(imgSplashBG, (0, 0))
    mainDisplay.blit(rot_center(imgSplashGreenCircle, ((frame % 360) * 10)), (-189, -189))
    mainDisplay.blit(rot_center(imgSplashRedCircle, ((frame % 360) * 10)), (453, 230))
    mainDisplay.blit(imgSplashFG, (0, 0))
    pg.display.flip()
    clock.tick(30)


Read more here: https://stackoverflow.com/questions/64950239/pygame-crashes-after-only-a-few-seconds-of-rendering-my-code

Content Attribution

This content was originally published by LetsdothisEpic at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: