Page MenuHome

Blender.BGL.glDrawPixels crashes when drawing more pixels then buffer size.
Closed, ArchivedPublicKNOWN ISSUE

Description

The following code crashes Blender in all releases and current CVS on Windows XP(confirmed) because of access violation cased by :

Blender.BGL.glDrawPixels(400,400, Blender.BGL.GL_LUMINANCE, Blender.BGL.GL_FLOAT, db)

trying to access more memory than has been allocated for the buffer, db. Note, the 400x400, when the buffer size is 200x200.

Full Code
#--------------------------------------------

import Blender

def blend(x, y, z):
#return (1.0 + x) / 2
#return (x + y) / 1.5
#return (x**2 + y**2)**0.5
return Blender.Noise.vlNoise((x*20,y*20,z*20), 1, 1, 3)

db = Blender.BGL.Buffer(Blender.BGL.GL_FLOAT, [200,200])
for y in range(-100, 100, 1):
for x in range(-100, 100, 1):
db[x][y] = blend(float(x+100)/200, float(y+100)/200, 0)

def draw():

global db

Blender.BGL.glRasterPos2i(100,100)
Blender.BGL.glDrawPixels(400,400, Blender.BGL.GL_LUMINANCE, Blender.BGL.GL_FLOAT, db)
Blender.Draw.Redraw()


Blender.Draw.Register(draw)

Event Timeline

Logged In: YES
user_id=103

Erm... why is this a bug? Opengl will crash then by definition... so you mean the py code needs a check?

Logged In: YES
user_id=3881

I understand that it's bad, but given that it actually crashes Blender, I'd have expected it to check.

Logged In: YES
user_id=461

Hi Tim and Ton,

Added a new version of the function with bounds checking. Previously it was created from macros, like most of BGL.c. There are other functions (5 more, I guess) that access buffers, too. Gotta investigate those.

--
Willian

Logged In: YES
user_id=461

Reopening this bug report. From Daniel Dunbar to the bf-committers list:

"The reason this was not done before is because it is not so
simple to check this (and the current code is not correct).
To accurately check this you need to look at all the parameters
to glDrawPixels, but then you also need to query the relevant
parts of the gl state, basically all the arguments to glPixelStore.
This is not particularly simple which is why I skipped it
before. Perhaps google can turn up some nice fragment of code
to do it correctly."

Logged In: YES
user_id=103

I still don't understand this bug; the python API apparently allows you to use low level C code, similar errors you will get in C too. So, either wrap such functions without your methods (so you can control better what happens) or just live with fact that our python draw code will just crash?

Logged In: YES
user_id=3487

I tried this and it didnt crash. what opengl drivers are you
using? - could we add a note in the BGL Docs that you need
to make sure you dont stuff up the buffer sizes and close
this bug?

Logged In: YES
user_id=3487

I tried this and it didnt crash. what opengl drivers are you
using? - could we add a note in the BGL Docs that you need
to make sure you dont stuff up the buffer sizes and close
this bug?

Logged In: YES
user_id=2923

moving to opengl tracker, since the user hasn't responded and appears to be opengl driver related

I know this is very old.
However I tested here and it crashes with Blender 2.48 and WindowsVista with NVidia 9600, drivers updated.

The problem I see is that since it is openGL, it doesn't help to do a try/catch in Python. In fact Blender print the "working" statement below.

""
try:
Blender.Draw.Register(draw)
print "working"

except:
print "not working (not crashing though"

""

This is a generic request to test your bug report and see if it is still an issue in 2.5alpha2 if so please let me know by making a comment in this report ie 'also in 2.5alpha2' and I will add it to the 2.5 bug list.

Matt Ebb (broken) changed the task status from Unknown Status to Unknown Status.Mar 26 2010, 6:15 AM