program exited with code 3

I made a savegame loader to load basic game information (level, etc) and then information for each of the player's units (soldiers in this case). When I save less than 20 units to the file, the loader works fine. But as I put more in, it crashes. gdb said "program exited with code 3". I looked this up on Windows list of error codes and it said "The system cannot find the path specified". I don't see how this could be applicable to my program.

You can download the source here: http://www.modshop.0sites.org/Source.rar
(this is just a test program derived from the source in my actual game. I wanted to make sure it worked before I put the final version into my game. Ignore the headers)

Any help would be greatly appreciated.
Last edited on
Can you post the function that parses your file data?
Sorry! I put up the wrong link. This one has the proper code.
http://www.modshop.0sites.org/Source.rar
Last edited on
Ok, I have narrowed down the problem to 2 lines of code. Both of them are push_back() calls to my unit vectors. Any idea why push_back() would work fine for around 20 times per vector, then fail (exiting code 3)?
Exit code 3 can mean an uncaught exception. Since you don't seem to use exceptions yourself, this is likely due to a std::bad_alloc exception, which generally means that your system has run out of memory.

This isn't particularly surprising, considering these lines in the code:
path.resize(stats.move);

With move never being initialized anywhere (like so many other variables in the program), you might attempt to resize the vector to a billion elements or something similar.
Even if you were to initialize tstat.move in main(), there's some problems left. Such as all operator= functions returning an object instance, but missing a return, which leads to some more undefined behavior. They should either return void or look like this:

1
2
3
4
5
const stat& operator=(const stat& rhs)
{
  [...]
  return *this;
}


stat::operator= doesn't copy move, by the way. So the unit's stats move member remains uninitialized.
Last edited on
Thank you! I would never have caught those! In my game, they would have been initialized, but I forgot to do that here as I was in a hurry to test this and get back to the actual game.

I added a try catch block, and it did catch an exception. Task Manager showed that almost all of the memory was in use, that explains the crash.

EDIT: It runs about 700x faster now too. Thanks again!
Last edited on
Topic archived. No new replies allowed.