So... all of us developers occasionally come across problems that we think we have no idea how to fix. And eventually, by luck, hard work or sometimes, in rare cases, talent, we manage to fix them. I just thought I'd start this thread for us to share such eureka moments, since they are pretty awesome when they happen.
As most of you probably know, I'm writing a game in C++ using the Ogre rendering engine. Yesterday, I implemented pathfinding according to the A* algorithm (very interesting algorithm and subject by the way). It seemed to work okay during testing, spitting out a sequence of tiles for my character(s) to follow. So far so good. This morning, I implemented a feedback mechanism that would highlight the potential path in green. That worked fine too, but what I noticed was that the path took a few seconds to be generated. This is on a 2.8Ghz 6 core Phenom II. So, I had heard that running in Debug mode seriously slows things down compared to release mode. I thought, this might be a good opportunity to make sure I can actually do a release build (I had never done a release build for my game before) and test whether the pathfinding is really slow or whether its just debug mode slowing everything down. I do the release build - works first time! - and start the game up. It crashes as soon as I try to generate a path. Again and again. But now, being in release mode, it doesnt tell me where the problem is. I know its occurring when I click, but not how or why. I google the problem, and someone mentions Intel's Parallel studio, which I download to help me track the problem down. I run the profiler, which makes the game run 10x slower than even debug mode, and while it turns up some minor problem, none of them are THE problem. Hmmm. I try running release with debug information, problem doesnt happen. Eventually I start inserting return statements into the method causing the problem, moving it down line by line until the exception occurs.
Turns out, a function that I used to find a reference, had no return value if nothing matched. In C#, the compiler will throw an error and say something like not all code paths have a return statement. Mine didnt, the function just ended. I changed it by simply inserting return 0, fixed the problem! I was overjoyed! Plus path generation is super speedy on release mode, clearly a debug mode issue.
As most of you probably know, I'm writing a game in C++ using the Ogre rendering engine. Yesterday, I implemented pathfinding according to the A* algorithm (very interesting algorithm and subject by the way). It seemed to work okay during testing, spitting out a sequence of tiles for my character(s) to follow. So far so good. This morning, I implemented a feedback mechanism that would highlight the potential path in green. That worked fine too, but what I noticed was that the path took a few seconds to be generated. This is on a 2.8Ghz 6 core Phenom II. So, I had heard that running in Debug mode seriously slows things down compared to release mode. I thought, this might be a good opportunity to make sure I can actually do a release build (I had never done a release build for my game before) and test whether the pathfinding is really slow or whether its just debug mode slowing everything down. I do the release build - works first time! - and start the game up. It crashes as soon as I try to generate a path. Again and again. But now, being in release mode, it doesnt tell me where the problem is. I know its occurring when I click, but not how or why. I google the problem, and someone mentions Intel's Parallel studio, which I download to help me track the problem down. I run the profiler, which makes the game run 10x slower than even debug mode, and while it turns up some minor problem, none of them are THE problem. Hmmm. I try running release with debug information, problem doesnt happen. Eventually I start inserting return statements into the method causing the problem, moving it down line by line until the exception occurs.
Turns out, a function that I used to find a reference, had no return value if nothing matched. In C#, the compiler will throw an error and say something like not all code paths have a return statement. Mine didnt, the function just ended. I changed it by simply inserting return 0, fixed the problem! I was overjoyed! Plus path generation is super speedy on release mode, clearly a debug mode issue.