« first day (2802 days earlier)      last day (814 days later) » 

10:09 AM
Hy anyone an idea why I get an
Segmentation fault (core dumped)
when I write the pixels

for (i = 0; i < image.heigth; i++) {
fwrite(&image.heigth + (i*widthInBytes), BYTES_PER_PIXEL, image.width, imageFile);
fwrite(padding, 1, paddingSize, imageFile);
}

before I write I free them
void freeImage(struct IMAGE image){
int i;

for(i = image.heigth -1; i == 0; i--){
free(image.rgb[i]);
}

free(image.rgb);
}

this is how my structure looks like
struct IMAGE{
struct RGB **rgb;
int width;
int heigth;
 
10:53 AM
@GonzoGonzales for starters, valgrind is Your friend :}
@GonzoGonzales also, can't see any allocations in Your snippet. And this part: fwrite(&image.heigth + (i*widthInBytes) looks particulary fishy to me. What, You take pointer of height field and add additional offset? o_0 Which goes... way past Your struct IMAGE
 
@Kamiccolo thank you for the tip I did not know this tool but it seems pretty nice.
thew allocation is done like this:

struct IMAGE image;
int i;

image.width = width;
image.heigth = heigth;
image.rgb = (struct RGB**) malloc(heigth*sizeof(struct RGB));

for(i = heigth -1; i == 0; i--){
image.rgb[i] = (struct RGB*) malloc(width*sizeof(struct RGB));
fread(image.rgb[i], width, sizeof(struct RGB), fp);
}

return image;
 
@GonzoGonzales bah, just like the last time, I'd suggest You to ditch those darn double pointers and loads of allocations just allocating one big blob of memory of the size width * heigh * pixel_size
 
Ok I will change it to this.
it will also make it easier to read
 

« first day (2802 days earlier)      last day (814 days later) »