Help, malloc and textures

Started by
1 comment, last by Scribe 18 years, 8 months ago
I've recently hit a snag in my coding. I read fonts from 8-bit bitmap info in memory and place into a malloc'd array in 32-bit rgba format. However, i constantly receive memory errors, if i use free(OpenGL_Texture) and also if i dont, the next malloc returns and error. to do this i use:

GLuint *OpenGL_Texture = (GLuint*)malloc( font_rows * font_width * 4 );
// 4 for the number of bytes (rgba)

i then run a loop like this( taking this out solves my problem!!! so error is prob here lol):

Uint32 Count = 0;

for( Sint32 y = font_rows-1; y > -1; y-- ) //read backwards for texture layout
{
   for( Sint32 x = 0; x < font_width; x++ )
   {
     OpenGL_Texture[Count] = 255; // or other number up2 255

     Count++;

     OpenGL_Texture[Count] = 255; // or other number up2 255

     Count++;

     OpenGL_Texture[Count] = 255; // or other number up2 255

     Count++;

     OpenGL_Texture[Count] = 255; // or other number up2 255

     Count++;

   }
}

any idea where im overstepping my bounds here? [Edited by - phantom on August 17, 2005 9:04:48 PM]
Advertisement
Your array is declared as a gluint, i.e. a 32-bit int. You are requesting enough memory for rows*width*4 *bytes*. In your loop, you are writing rows*width*4 *integers*. There's the problem. Just declare your OpenGL_Texture as GLubyte*.
ARGH ur right!!! I'm soooo stupid. Thankyou.

I even got to looking at my malloc ASM lol.

This topic is closed to new replies.

Advertisement