diff pytouhou/ui/renderer.pyx @ 301:6f1ca1cb5238

Avoid segfaults in the unlikely case a huge number of sprites is rendered.
author Thibaut Girka <thib@sitedethib.com>
date Sat, 10 Mar 2012 20:30:55 +0100
parents d3ba32a9096e
children f3099ebf4f61
line wrap: on
line diff
--- a/pytouhou/ui/renderer.pyx
+++ b/pytouhou/ui/renderer.pyx
@@ -24,7 +24,7 @@ from .sprite cimport get_sprite_renderin
 from .texture cimport TextureManager
 
 
-MAX_ELEMENTS = 10000
+MAX_ELEMENTS = 640*4*3
 
 
 cdef class Renderer:
@@ -47,6 +47,9 @@ cdef class Renderer:
         indices_by_texture = {}
 
         for element in elements:
+            if nb_vertices >= MAX_ELEMENTS - 4:
+                break
+
             sprite = element._sprite
             if sprite and sprite.visible:
                 ox, oy = element.x, element.y