stephanh42 / RacketGL

Extended OpenGL bindings for Racket
Apache License 2.0
48 stars 14 forks source link

Crash when calling glBufferData #4

Closed cryovat closed 12 years ago

cryovat commented 12 years ago

Hi,

First of all, thanks for your work on this library!

I've been tinkering with it for some time now, but whenever I try to use vertex buffer objects, I always end up crashing hard when trying to get data into the buffer. I'm using code like the following:

(define verts (make-f32vector 16))
(define verts-size (* (ctype-sizeof _float) (f32vector-length verts)))
(define vbo (u32vector-ref (glGenBuffers 1) 0))
(glBindBuffer GL_ARRAY_BUFFER vbo)
(glBufferData
           GL_ARRAY_BUFFER
           (s32vector verts-size) ; Length of array in bytes
           (f32vector->cpointer verts) ; Causes crash, #f is fine
           GL_STATIC_DRAW)

Is the crash caused by errors in my code, or is there any deeper issues at play here?

stephanh42 commented 12 years ago

Hi Cryovat,

This seems definitely a bug in the RacketGL binding.

The second parameter of glBufferData should simply be an integer, not a vector, but the binding incorrectly requires a vector.

If you are adventurous, the following should fix it (untested):

Replace in readspec.rkt the line

(cons "GLsizeiptr" (pointer-to '_int32))

by

(cons "GLsizeiptr" '_int32)

and then regenerate the bindings.

Please note that I haven't tested VBOs at all yet, so expect some roughness along the way.

Stephan

On 13-05-12 23:33, cryovat wrote:

Hi,

First of all, thanks for your work on this library!

I've been tinkering with it for some time now, but whenever I try to use vertex buffer objects, I always end up crashing hard when trying to get data into the buffer. I'm using code like the following:

(define verts (make-f32vector 16))
(define verts-size (* (ctype-sizeof _float) (f32vector-length verts)))
(define vbo (u32vector-ref (glGenBuffers 1) 0))
(glBindBuffer GL_ARRAY_BUFFER vbo)
(glBufferData
            GL_ARRAY_BUFFER
            (s32vector verts-size) ; Length of array in bytes
            (f32vector->cpointer verts) ; Causes crash, #f is fine
            GL_STATIC_DRAW)

Is the crash caused by errors in my code, or is there any deeper issues at play here?


Reply to this email directly or view it on GitHub: https://github.com/stephanh42/RacketGL/issues/4

stephanh42 commented 12 years ago

I pushed this change (actually with _intptr rather than _int32).

cryovat commented 12 years ago

Wow, thank you for the incredibly fast reply and fix. You rock! :-)