• entries
  • comments
  • views


Sign in to follow this  


Took me 3 fucking hours to find the bastard, but I did it. To be fair though, I was talking to Meghan for half of the time (and she was getting more of my attention lol) and I was arguing with some morons as well.

When I first started, I decided that I'd enable my memory detection, and then step through the game from start to finish. I get going and I notice that I have a memory leak as soon as the game starts (well, not as soon as it starts, but in the very first state.) I spent an hour and a half trying to find this bug. Since the memory leak detector was giving me part of a filename in the log, I assumed it had to do with my texture (in a way it did, but not how I was thinking.) So I spent a bunch of time trying to narrow it down.

Come to find out, the problem was my GetAbsoluteFileName() function. I had it set to "const std::string &GetAbsoluteFileName()", then I had a static string inside that I was setting at the beginning of the program and returning. Yea, I fail.

Anyway, that took half of my time. I moved on finally and was jumping all over the place trying to find this bug. Then I noticed that I only had 100 entities in my list (there should be 101; 100 zombies and the character.) So I go through and log all of the Character destructor calls and log the names of the character. Since they're stored in a map, they weren't stored in order, so I had to manually put them in order. Come to find out, Zombie89 is being overwritten. An hour later, I end up in my StringOps::Hash() function. Somehow my Hash() function returns the same value for "Zombie89" as it does for "Zombie98" (only these two; everything else works perfectly fine. Zombie91 and Zombie19 are different, 31 and 13, etc.)

For reference, this is the Hash() algorithm that I came up with and was using before:

int Results = 1;
for(unsigned int Index = 0; Index < String.size(); ++Index)
Results = String[Index] * (Index + Results);
if(String.size() > 0)
return Results / (int)String.size();
return Results;

I searched all over the web and now I'm using the following:

unsigned int Results = 1315423911;
for(std::size_t Index = 0; Index < String.size(); ++Index)
Results ^= ((Results << 5) + String[Index] + (Results >> 2));
return Results;

And now everything works. Onward to better stuff now.

Oh, and I switched from the somewhat-8 direction movement to full 8 direction movement (with graphics.) I'll be adding a strafe key like was suggested so you can strafe whatever direction you're facing.
Sign in to follow this  

1 Comment

Recommended Comments

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now