I'm having problems with a function that writes image data to a buffer. Heres where I allocate the memory in main():
Code:
fb = malloc(sizeof(int)*FONTSET_WIDTH*FONT_WIDTH*FONTSET_HEIGHT*FONT_HEIGHT);
And heres my function along with struct definition and global pointer declaration:
Code:
struct font_buffer
{
Uint32 pixels[FONTSET_WIDTH*FONT_WIDTH*FONTSET_HEIGHT*FONT_HEIGHT];
}; typedef struct font_buffer font_buffer;
struct screen_buffer *sb = NULL;
struct font_buffer *fb = NULL;
void LoadBitmapFont()
{
SDL_Surface *font=NULL;
font = SDL_LoadBMP("Font.bmp");
unsigned image_width=FONTSET_WIDTH*FONT_WIDTH;
unsigned image_height=FONTSET_HEIGHT*FONT_HEIGHT;
unsigned image_size = image_width * image_height * sizeof(int);
unsigned i, inc=sizeof(int);
Uint32 *src=NULL, *dst=NULL;
for(i=0; i<image_size; i+=inc)
{
src = font->pixels+i;
dst = fb->pixels+i;
*dst = *src;
}
SDL_FreeSurface(font);
font=NULL;
}
My debugger just says I got segfaults If I dont call this function then the program runs, so it seems as if there must be a problem with the function. Can someone please tell me whats wrong with it? Thanks.