This doesn't make any sense. Why is fread returning -16 million when only 2 bytes are supposed to be read, and only when the image's width is over 256 pixels. A 1024x85 image reads correctly, but 128x23 is returning -16 million for both width and height. Here's what I have (note: I'm reading a TGA file here):
Why, for a 256x51 or 128x23 image (and other sizes with a width 256 pixels or less) am I getting negative 16 million for the width and height, when a 1024x85 has it read correctly? What's more is that I haven't even changed this part of the code in a very long time and it's worked just fine well beforehand. It's just now acting up and it's causing unhandled exceptions to occur (expected since 2.9 billion (yes, billion) bytes being changed in memory is bound to cause some byte my program doesn't have permission to change to change). Any ideas why this is happening? The pointers are fine (those, too, haven't been touched for a very long time (nearly a year even).
fseek(FileHandle, 12, SEEK_SET); // skip to the width and height part of a TGA image
MainData->Info.biSize = 40; // the size of the struct, always 40 in my case (due to true color being used)
fread(&MainData->Info.biWidth, 2, 1, FileHandle); // problem!
fread(&MainData->Info.biHeight, 2, 1, FileHandle); // problem!
MainData->Info.biPlanes = 1; // always 1
MainData->Info.biBitCount = 32; // number of bits per pixel, always to be 32 for TGA images (due to alpha channel)
MainData->Info.biCompression = BI_RGB; // no compression used
MainData->Info.biSizeImage = MainData->Info.biWidth*MainData->Info.biHeight*4; // problem (2.9 billion!?)
MainData->Info.biXPelsPerMeter = 2835; // resolution in pixels per meter - this can be anything
MainData->Info.biYPelsPerMeter = 2835;
MainData->Info.biClrUsed = 0; // always 0 in my case
MainData->Info.biClrImportant = 0; // same here
fseek(FileHandle, 18, SEEK_SET); // skip to the main image data
fread(MainImageData, 1, MainData->Info.biSizeImage, FileHandle); // read the main image data // reads in BGRA format