Thread: Weird access violation error with stack

  1. #1
    Registered User
    Join Date
    Sep 2005

    Weird access violation error with stack

    In my game, I have this piece of code:
    if (Game::EnemiesToSpawn.empty())
          Game::isSpawned = false;
          level.setCurrentLevel(level.getCurrentLevel() + 1);
          SpawnEnemy(, enemy_Knight);
    I used some ghetto-style debugging. This game library does not have a debug build, so I cannot step-through. What I did was have it write to a text file every couple lines to narrow it down (not shown obviously). It errors out right before the SpawnEnemy call.

    It does not even get to the first line of the actually SpawnEnemy function. Enemy_Knight is simply an integer enumerator. EnemiesToSpawn is a stack of ints. There is nothing else it could be except for the stack.

    What's weird is I will get an access violation error RANDOMLY. It's always on this line, but it occurs anywhere from 2-10 minutes of game play. I don't get why it does this - what exactly would cause an error like this? I would think it would maybe occur if the stack is empty when I tried to top() it, but the if statement is clear and straightforward - that can't be the case.


  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    New Zealand
    Here's the problem:
    This game library does not have a debug build, so I cannot step-through
    It could be anything from memory corruption to lack of multi-threading synchronisation, and is nothing directly related to the code posted.
    You can try commenting out stuff until the problem doesn't happen, but with up to 10 minutes to reproduce the problem, that could take a very very long time!
    You need to make a debug build and use that and stop shooting yourself in the foot.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    If the library doesn't have source code, then you are stuffed. For the next project, consider getting a library that has debug/source code available.

    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. Istream::Release access violation? [C++]
    By A10 in forum Windows Programming
    Replies: 10
    Last Post: 01-13-2009, 10:56 PM
  2. Stack trace for access violation
    By locksleyu in forum C++ Programming
    Replies: 2
    Last Post: 12-11-2008, 03:01 PM
  3. Replies: 3
    Last Post: 07-17-2008, 08:45 AM
  4. Weird Acception Violation :: MFC
    By kuphryn in forum Windows Programming
    Replies: 1
    Last Post: 07-15-2002, 09:06 PM
  5. 0xC0000005: Access Violation
    By Strider in forum Windows Programming
    Replies: 3
    Last Post: 11-07-2001, 02:46 PM