The First Bug

I have worked on ctp.h/cpp this week. Player walk logic is in it. There were too many global variables used, so I decided to form them into classes. I have created two classes, one for walkbox and one for routes. I manage to move most of the globals, and move to Scripts.h/cpp unaware of the lurking problems.

When I was testing the changes in the script files, I found some inventory items causes segmentation faults. The problem was that I used a pointer as parameter, and it was passed as value, not referance.

It was fairly easy to fix since I can pinpoint which commit broke it, and see the difference I made. But while I test it, I forgot to take an item from the first room, and when I came back, I found out, the character can not move.

First find the commit that broke it, that is the easiest part. Okey, I found the commit that the problem emerged, but the changes are small and simple. I could not found anything that may cause that problem, or any problem. So I start to watch the values that assigned, but the did not mean anything to me. Then I though to compare them with the real ones, and that give me some bizarre differences.

The first loop was fine, but in the second one, one value was wrong. than it gets completely different. The weird part was that the loop counts was different too, that was my clue. There was a assignment out of index in a matrix. That was not a problem before since the assigned value will be overwritten in next loop, but since I removed the matrix and moved the variable in to a class, where the assignment actually write the value is unpredictable, and might broke all the walking logic. I talked with my mentor about this, and consulted dreammaster too( thank you again). I have added a little code for not changing the behaviour, but there is room for improvement.

This was the first bug that I did not cause, and I am happy to be able to work on it. But I have to say, knowing how c++ works and being able to think like it is two very different things.