Chào các bạn! Vì nhiều lý do từ nay Truyen2U chính thức đổi tên là Truyen247.Pro. Mong các bạn tiếp tục ủng hộ truy cập tên miền mới này nhé! Mãi yêu... ♥

Bugs In Unexpected Positions


It's been a while since my last post, and that's because I haven't been working on the game as much now that school has started back up for me. However, I have been working on it, and today I ran into a rather... peculiar computer bug. Story time!

So here I was, implementing a sprite into the system in a way that allows it to have varied colors, when suddenly:

For some reason, it came in stretched! This wasn't the first time running into this problem, but it was the first time that I have had it happen with this type of sprite. "Well, this is odd," I thought. The pictures made by my girlfriend were working perfectly fine, but the first one made by me decides to break. As I said, it wasn't the first time happening, but unfortunately I didn't have the option of the same fix as last time.

Previously, I was actually under the impression that it was a bug in the c# system. Instead, as any images made by my computer break but not ones made on other computers, I came to the conclusion that it was something worse. Much, much worse. This time I had to get my hands dirty.

This particular image is in the Windows Bitmap format, otherwise known by its file extension "bmp." As any good programmer does, soon as I had a problem, I looked to the internet. Here I found the specification for how the files are setup, as they have more in them than pixel data.

I found what I thought was quite the archaic gem at the time:

What. Pixels per... meter?! I burst into laughter upon seeing these lines, especially at the fact that they were specifically listed as "unreliable." Well, it was funny and all, but I had to take my next step in the journey, and now that I knew that the first 54 bytes took up the header, I had to get to work.

For a little background information, all of the images I am using for this specific task of are the same format: that is same color palette, file type, and size. Knowing this, I figured that a working image and a "broken" image should be the same in those first 54 bytes, so I got those numbers and put them onto the screen, looking for a difference, which I found:

Ironically, the part of the specification that I laughed at was the exact part that was causing me problems! That's right: the pixels per meter! How unreliable indeed. Fast forward a little bit, and I made a program which switches those 4 different bytes to the set that works:

And then turns out that it was the right solution! Welcome to programming:

I had done it. I figured out a super strange bug and created a crazy workaround to fix it.

Or so I thought.

Turns out, I fixed it the most completely wrong and horribly complicated way.

As I was typing this, my girlfriend pulled up her computer and got to digging around. She inspected my "broken" images with the correct ones, and managed to find the difference. For some odd reason, my computer was set to make the images at a resolution of 72 pixels per inch, as opposed to what is apparently correct at 96 pixels per inch.

...Shows you the difference in our problem solving strategies doesn't it? :P

Well, now that that's fixed everything should be right, but good grief that was a wild ride.

That's all for this time, but we'll have some (prettier) screenshots of our progress next time!

Bạn đang đọc truyện trên: Truyen247.Pro