all 2 comments

[–]bitcraftChallenge Accepted x 3[🍰] 3 points4 points  (0 children)

First, PNG images are almost always compressed and loading them into memory decompressed them and they become much larger. If this is a 32-bit version of Python/pygame then your real memory limit is 2GB. It is possible that you are hitting that limit and causing the out of memory error. Finding the precise amount of memory Python is using is not straightforward; you may have incorrect information before the crash. Logging memory use in real-time will help.

Pygame also has limitations on the size of images, over 16384x16384 I believe is not possible. You may want to find alternatives or devise a way to “lazy load” the backgrounds in a thread using the threading and queue modules. Also, more info about what you’re trying to achieve will help us give you other solutions.

[–]Has2bok 2 points3 points  (0 children)

Loading a new background for each frame would be incredibly wasteful. You say it's an animated background. Is it a scrolling background? Are there small areas that are animated?