comparison 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
comparison
equal deleted inserted replaced
300:da53bc29b94a 301:6f1ca1cb5238
22 22
23 from .sprite cimport get_sprite_rendering_data 23 from .sprite cimport get_sprite_rendering_data
24 from .texture cimport TextureManager 24 from .texture cimport TextureManager
25 25
26 26
27 MAX_ELEMENTS = 10000 27 MAX_ELEMENTS = 640*4*3
28 28
29 29
30 cdef class Renderer: 30 cdef class Renderer:
31 def __cinit__(self): 31 def __cinit__(self):
32 # Allocate buffers 32 # Allocate buffers
45 cdef unsigned short nb_vertices = 0 45 cdef unsigned short nb_vertices = 0
46 46
47 indices_by_texture = {} 47 indices_by_texture = {}
48 48
49 for element in elements: 49 for element in elements:
50 if nb_vertices >= MAX_ELEMENTS - 4:
51 break
52
50 sprite = element._sprite 53 sprite = element._sprite
51 if sprite and sprite.visible: 54 if sprite and sprite.visible:
52 ox, oy = element.x, element.y 55 ox, oy = element.x, element.y
53 key, (vertices, uvs, colors) = get_sprite_rendering_data(sprite) 56 key, (vertices, uvs, colors) = get_sprite_rendering_data(sprite)
54 rec = indices_by_texture.setdefault(key, []) 57 rec = indices_by_texture.setdefault(key, [])