The latest BMP I made crashes the program, other BMPs work fine

Started by
12 comments, last by 21st Century Moose 7 years, 9 months ago

I will say that I don't know much about the loader you are using. But, I will say that I know that BMP has several different actual formats. They all start with the 0x42 in the header, but other parts of the header indicate other things, like bits per pixel, compression method, etc... Some loaders don't take into account all BMP types(and the same can be said about other image types as well). BMP has one notorious thing called RLE(run-length encoding) as a form of compression it can use. It is compression based on turning a line of equal pixels into a single pixel and an accompanying number saying how many it is actually. So images with lots of space being the same color,(think flat shaded pixel art, or outer space, or anything similar) it will have much saved space. If the image is all a single color, the only space it needs(besides headers, etc...) is the color, and how many pixels it is repeated, which would be all of them. So in just a few of bytes the whole image is defined. But, if the image is full of noise, the "compression" ends up inflating, with every pixel requiring the value, and the amount(which would just be 1). I detail this tidbit also because many loaders don't know how to load this format, so if you saved your new BMP that way, it may be the case.



Advertisement

The loader is probably failing to load the image, returning a null pointer, and your application doesn't handle this case properly.


I worked this out yesterday evening... I opened my image in paint and copied it into another file* then saved it as a 24 bit image, and it worked. I never saw any reason to save as 24 bit, I always used 32 bit plus alpha channel. What's odd is that my valid image files are 24 bit, but I remember saving them as 32 bit plus alpha layer only 3 months ago. I also made a mistake because I thought alpha layers had something to do with image masking, but that's a different thing. I remember wrong! I knew my problem wasn't the directory because it was all in the same folder, no chance of confusing a backslash for a forward slash, as there weren't any.

*not even necessary, this part.

I'll look up debugging on Youtube. I did find something in the debugger that showed my image hadn't loaded. image1 and image2 looked very different in the debugger. The bad image showed up as 0x0 and the good image appeared to have a location in memory, or a number associated with it.

Logging in from unsecured wireless, I hope no-one steals my password (October 22, 2016)

In general, failing to load images can happen. Images may get corrupted or missing (broken archive, broken disk, wrong filename, etc). You have to handle it in some way.

I generally, just fail to start the game in such a case. Other options can be to skip drawing such images (but that would only work if you have a replacement or it's a minor enhancement).

Yes, alpha channels can be problematic in BMP files because they're so rarely seen: typically if somebody wants alpha they'll be using a different file format. What this means is that a lot of editing software, and loaders, just don't support alpha in BMPs.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement