Menu

Strange memory bug with code

TinyMage
2007-12-27
2012-09-26
  • TinyMage

    TinyMage - 2007-12-27

    My program is crashing at runetime. It says "Program.exe" has stopped working blah blah blah.

    I finally traced the problem code down to this:

    struct RandomTile
    {
    unsigned short int tilegraphic;
    unsigned short int objectgraphic;
    unsigned char type; // type of tile, barrier etc
    unsigned short int door; // index to door table
    unsigned short int text; // index to text table
    unsigned short int treasure; // index to treasure table
    };

    class RandomMap
    {
    public:

    private:
    
        RandomTile tiles[500][500];
    

    };

    When I decrease the size of the tile array to 300 x 500 the program runs fine. But anything over 400 will crash it.

    I am on a system with 766 megs of ram free. Running windows vista.

    I did a sizeof on my engine class ( which allocates 1 instance of RandomMap ) and it says about 2 megs.

    The only thing I can think of is some kind of bug with the devcpp compiler.

     
    • Nobody/Anonymous

      I had this before. For some reason there is a maximum allowed object size for the arrays you create. I was making a 3D square array and above a certain size the code would crash whereas below the critical size it would run without any problems. I've read somewhere that the maximum size is something to do with certain system parameters, but it seems totally lame to me that there is a limit on the arrays you can make that isn't simply the amount of physical memory.

       
    • Kurgusov

      Kurgusov - 2007-12-28

      Have you checked that you have not exceeded the bounds of the array in some forloop or other,
      To say its a bug with devcpp's compiler is laughable.

       
    • TinyMage

      TinyMage - 2007-12-30

      "Have you checked that you have not exceeded the bounds of the array in some forloop or other,
      To say its a bug with devcpp's compiler is laughable."

      The array is completely unused it is just declared inside class RandomMap and then an instance of RandomMap is declared.

      RandomMap is also unused.

      I suppose its my fault somewhere but I just cannot figure out where.

      I actually recompiled the code in VC++ express 2008 and still got the same problem. I just cannot figure out what could be wrong so I rewrote my engine class as a set of functions and it worked fine. Oh well who knows.

       

Log in to post a comment.