VBO crash

  • Follow


Hi!
I get external triangle data as an array of double. I create an GLfloat 
array of equal size to save memory on the card. The app crashes if I 
want to delete that temporary array after calling glBufferDataARB.
Does anybody know why?

Thanks a lot, Jan.

....

if(pVertexData)
{
m_vType[0] = true;
GLfloat *pTempFloatData = new GLfloat[vertices*3];
for(int i=vertices*3; i>=0; i-=3)
{
pTempFloatData[ i ] = static_cast<GLfloat>(pVertexData[i]);
pTempFloatData[i+1] = static_cast<GLfloat>(pVertexData[i+1]);
pTempFloatData[i+2] = static_cast<GLfloat>(pVertexData[i+2]);
}
glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_vbo[0]);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, vertices*3*sizeof(GLfloat), 		 
pTempFloatData, GL_STATIC_DRAW_ARB);
delete [] pTempFloatData;	// crashes at this point
pVertexData = 0;
}

....

if(m_vType[0])
{
glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_vbo[0]);
glVertexPointer(3, /*GL_DOUBLE*/GL_FLOAT, 0, pVertexData);
glEnableClientState(GL_VERTEX_ARRAY);
}

....

glDrawArrays(GL_TRIANGLES, 0, vertices );
glDisableClientState(GL_VERTEX_ARRAY);
0
Reply aiscape (8) 12/15/2004 5:43:46 PM

Jan Boehme wrote:

> Hi!
> I get external triangle data as an array of double. I create an GLfloat
> array of equal size to save memory on the card. The app crashes if I
> want to delete that temporary array after calling glBufferDataARB.
> Does anybody know why?
> 
> Thanks a lot, Jan.
> 
> ...
> 
> if(pVertexData)
> {
> m_vType[0] = true;
> GLfloat *pTempFloatData = new GLfloat[vertices*3];
> for(int i=vertices*3; i>=0; i-=3)
> {
> pTempFloatData[ i ] = static_cast<GLfloat>(pVertexData[i]);
> pTempFloatData[i+1] = static_cast<GLfloat>(pVertexData[i+1]);
> pTempFloatData[i+2] = static_cast<GLfloat>(pVertexData[i+2]);
> }

You're doing an out-of-bounds access. i starts at vertices*3, which is one
element beyond the array you allocated, and you write to that location and
two more. It's likely that this access destoyed internal meta data that the
memory management system needs, so the next time you allocate oder
deallocate memory, it crashes.

> glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_vbo[0]);
> glBufferDataARB(GL_ARRAY_BUFFER_ARB, vertices*3*sizeof(GLfloat),
> pTempFloatData, GL_STATIC_DRAW_ARB);
> delete [] pTempFloatData;     // crashes at this point
> pVertexData = 0;
> }
> 
> ...
> 
> if(m_vType[0])
> {
> glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_vbo[0]);
> glVertexPointer(3, /*GL_DOUBLE*/GL_FLOAT, 0, pVertexData);
> glEnableClientState(GL_VERTEX_ARRAY);
> }
> 
> ...
> 
> glDrawArrays(GL_TRIANGLES, 0, vertices );
> glDisableClientState(GL_VERTEX_ARRAY);

0
Reply Rolf 12/15/2004 11:12:12 PM


Hi Rolf!

Rolf Magnus wrote:
> You're doing an out-of-bounds access. i starts at vertices*3, which is one
> element beyond the array you allocated, and you write to that location and
> two more. It's likely that this access destoyed internal meta data that the
> memory management system needs, so the next time you allocate oder
> deallocate memory, it crashes.

Thanks a lot, Jan.
0
Reply Jan 12/16/2004 8:39:20 AM

2 Replies
113 Views

(page loaded in 0.051 seconds)

Similiar Articles:








7/16/2012 7:11:59 PM


Reply: