4096 sprite limit

Bug #1178470 reported by David Griffin on 2013-05-09
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
PyGL3Display
High
David Griffin

Bug Description

Thins are OK with 4096 sprites. Adding the 4097th sprite causes things to fall down, however. Given it's a power of 2 number, that's probably not a coincidence.

David Griffin (habilain) on 2013-05-09
Changed in pygl3display:
importance: Undecided → High
assignee: nobody → David Griffin (habilain)
status: New → Confirmed
tobs12 (hans1215) wrote :

With this I get the exception below:
-------------------------------------------------------
import sys,os

from pygl3display import *

GLCommon.initEnvironment((1680,1050),fullscreen=True)

import pygame
from pygame.locals import *

floor=loadImage('block1.png', wrapped=True)
spr=[ list( list() for x in range(80) ) for x in range(80) ]

for y in range(70):
    spr.append
    for x in reversed(range(70)):
        spr[y][x]=Sprite(image=floor)

while 1:
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key== pygame.K_ESCAPE:
                sys.exit()
        if event.type == pygame.QUIT:
            sys.exit()

    for y in range(60):
        for x in range(60):
            spr[y][x].setPosition( ( -100+(x+y)*16, 500+(y-x)*8 ) )

    GLCommon.doTasks()

---------------------------------

Traceback (most recent call last):
  File "lots_sprites_error.py", line 37, in <module>
    GLCommon.doTasks()
  File "c:\Python27\lib\site-packages\pygl3display\glcommon.py", line 253, in doTasks
    shader.doTasks(layer=layer, target=target)
  File "c:\Python27\lib\site-packages\pygl3display\infrastructure.py", line 375, in doTasks
    client.doTasks(layer, target)
  File "c:\Python27\lib\site-packages\pygl3display\infrastructure.py", line 114, in doTasks
    vertexArrays.bind()
  File "c:\Python27\lib\site-packages\pygl3display\vertexarrays.py", line 388, in bind
    ctypes.byref(data, mn))
  File "latebind.pyx", line 44, in OpenGL_accelerate.latebind.Curry.__call__ (src\latebind.c:832)
  File "c:\Python27\lib\site-packages\OpenGL\GL\VERSION\GL_1_5.py", line 93, in glBufferSubData
    return baseOperation( target, offset, size, data )
  File "errorchecker.pyx", line 50, in OpenGL_accelerate.errorchecker._ErrorChecker.glCheckError (src\errorchecker.c:854)
OpenGL.error.GLError: GLError(
 err = 1281,
 description = 'ung\xfcltiger Wert',
 baseOperation = glBufferSubData,
 cArguments = (
  GL_ARRAY_BUFFER,
  0,
  313604,
  <cparam 'P' (084E0020)>,
 )
)

David Griffin (habilain) wrote :

Verified that this is the same issue as the 4096 sprite limit in the report. Reason for not seeing any errors initially was that error reporting under the cffi backend doesn't seem to work, but that's a separate bug.

tobs12 (hans1215) wrote :

Thanks for your fast reply.
Do you think the number 4096 is a limit of the hardware or OpenGL?
Best regards

David Griffin (habilain) wrote :

As stated, it's a bug. Certainly not a hardware limit.

The bug was simply that when allocating buffers, I was allocating in items to store and not in bytes, which obviously caused problems as OpenGL didn't allocate enough to store all the data.

This should be fixed in revision #103. A release will follow after I manage to fix the bug in cffigl which was prevents error detection. If you want a quick fix though, just download the current revision.

Changed in pygl3display:
status: Confirmed → Fix Committed
tobs12 (hans1215) wrote :

Thanks!

tobs12 (hans1215) wrote :

Hello,
I tried revision #103.
The crash is fixed.
But not all sprites are displayed.
Roughly 50x80 is displayed with this example.
The last drawn sprite is distorted. See attachment bug_screen.png.
-------------------------------------------
import sys,os

from pygl3display import *
configure('pygame')

GLCommon.initEnvironment((1680,1050),fullscreen=True)

import pygame
from pygame.locals import *

floor=loadImage('block1.png', wrapped=True)
spr=[ list( list() for x in range(80) ) for x in range(80) ]

for y in range(80):
    for x in reversed(range(80)):
        if x%10 == 0 and y%10 == 0:
            continue
        spr[y][x]=Sprite(image=floor, position = ( -100+(x+y)*16, 500+(y-x)*8 ) )

while 1:
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key== pygame.K_ESCAPE:
                sys.exit()
        if event.type == pygame.QUIT:
            sys.exit()

    GLCommon.doTasks()
-------------------------------------------

David Griffin (habilain) wrote :

How bizarre. Reopened the bug and I'll look into this tomorrow.

Changed in pygl3display:
status: Fix Committed → Confirmed
tobs12 (hans1215) wrote :

Here is what I have installed:
Python 2.7.2 on Windows 7 64bit
PyOpenGL-3.0.2.win32, PyOpenGL-accelerate-3.0.2.win32-py2.7
pygame-1.9.1.win32-py2.7

David Griffin (habilain) wrote :

Thanks for the version information, but it's not relevant here. I've reproduced the bug on my end, and what I'm seeing is this:

1) The 4096th sprite is distorted
2) Sprites 4097 is highly distorted
3) Sprites 4098 and above do not render

David Griffin (habilain) wrote :

And an addendum: not hardware specific either, as reproduced on both Intel and ATI graphics now. Interestingly with ATI graphics I only get very high amounts of distortion - all sprites render, but I think with texture coords being (0,0). On Intel this only sometimes happened for sprite 4097...

David Griffin (habilain) wrote :

Slightly embarrassing mistake on my part. I corrected the code in one place and neglected to do so in another. Hence I was only uploading the first N bytes rather than N items (N = number of vertexes). Hopefully fixed this time (r104)

Changed in pygl3display:
status: Confirmed → Fix Committed
tobs12 (hans1215) wrote :

Thanks for the fix. It works for me.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Related questions