Thread: Random errors

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    102

    Random errors

    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!


    EDIT:
    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.
    Last edited by JJFMJR; 03-13-2009 at 07:48 PM.
    My Favorite Programming Line:
    Code:
    #define true ((rand() % 2) ? true : false)

  2. #2
    Registered User
    Join Date
    Apr 2004
    Location
    Ohio
    Posts
    147
    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 --
    Last edited by leeor_net; 03-14-2009 at 12:40 AM.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    looks like using not initialized varables somewhere
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Registered User
    Join Date
    Apr 2007
    Posts
    102
    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!
    My Favorite Programming Line:
    Code:
    #define true ((rand() % 2) ? true : false)

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by JJFMJR View Post
    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.
    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:
    1. Recognize as "this is deleted memory".
    2. Identify that you are getting the wrong data.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Question for Random class
    By joenching in forum C++ Programming
    Replies: 2
    Last Post: 03-20-2005, 11:22 PM
  4. Counting number from a random file
    By kamisama in forum C Programming
    Replies: 42
    Last Post: 02-22-2005, 05:16 PM
  5. non repeating random number generation?
    By gencor45 in forum C# Programming
    Replies: 1
    Last Post: 02-08-2005, 05:23 PM