Hey everyone, I'm working on a current game project right now. I'm receiving some weird problems/errors. Since it is a massive amount of code, I'm going to try to not post any, but if needed, just let me know :).
Anyway, I'm using the Win32 and OpenGL APIs. I'm also using the CodeBlocks IDE.
Here's the first error. One of the main models will randomly on a compile, with no changes in code, show extremely abnormal and incorrect colors. (It appears as though it is being textured by another object in the scene. However, this only happens once every 20 compiles or so, without any change to code. Also, when I switch the build target to "Release" in my IDE, it has the error virtually 100% of the time, once again with no change in code.
Another is a very interesting error. In an attempt to draw some 3d text to the screen, I found an error. I bracketed the if statement that checks a boolean determining whether or not to draw the text, and placed a cout with a random sentence to let me know it hasn't crashed before drawing the text. Yet, when I added the cout and brackets, it worked fine. I've continued debugging, but everytime I remove the cout statement, it crashed, yet with it there, it does not. I've left the brackets and commented the cout, it fails, uncomment and it works fine! The cout statement has absolutely nothing to do with the drawing of the text in anyway shape or form.
If anyone can give me some sort of help, I'd grealty appreciate it. I'm a pretty experienced programmer, but my regular techniques of debugging don't seem to work to well on these haha! If you have come across something like this, or know some C++ information that could cause this that I may have skipped over, please feel free to share. Thanks for taking time to read!
Managed to fix the second problem with the text and std::cout. For some reason, my text that I was displaying as a const char* was being deleted deep inside my text class before it was being drawn. Not exactly sure how it worked every few times, but it's fixed now haha.
I recently went through a series of similar seemingly random errors. I can tell you right now that, more than likely, you've got bad or improperly pointers.
I don't know how GCC/GDB works but I know that I was able to locate all of the problems in my code by examining hex values of various values throughout my program. When I found things like 0xBAADF00D, 0xCDCDCDCD, 0xFDFDFDFD, etc. I knew that there was a problem somewhere.
I found that I cleaned up just about every single one of my errors by cleaning up and rewriting the various parts of my code that used raw pointers or C-Style dynamic arrays. I realized that I should just use STL containers as it signifigantly cleans up the code and almost makes it hard to introduce pointer bugs. They're also a lot easier to use once you get past the template syntax.
Hope that helps --
looks like using not initialized varables somewhere
Yet another excuse to write portable code. If you can build your program on Linux, you can run it through Valgrind, which will immediately expose any uninitialized variable usage.
On Windows, you're pretty much stuck with expensive commercial products like Boundschecker, Purify, etc
Hmm, I've gone through searching for pointer errors or un-initialized variables as you all have suggested, I thought the same thing originally as well. However, I did not find anything significant after cleaning up all the code. I've actually been able to solve the first error issue. The const char* passed into the text was actually being deleted before it was fully drawn. I'm not exactly sure why it worked sometimes and not others, but it works 100% now thanks.
As for the other, through some thorough debugging, i've labeled the error down to a problem loading up the model file. I will closely examine the file loading process and resolve the issue. Thanks again everyone!
It works sometimes because only some other times does the memory get overwritten with something else before the text is fully drawn. It is a very common problem. It is easier to detect this if you implement your own free/delete function that overwrites the freed memory with some constant value (e.g. 0xAA) that you can:
Originally Posted by JJFMJR
1. Recognize as "this is deleted memory".
2. Identify that you are getting the wrong data.