PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Possible stack overflowing. Could use some help.

You'll have to forgive my ignorance when it comes to these sorts of issues. I'm new to C++ and even newer to programming on the PPC. So when it comes to things like limited memory and stack overflows, I have to admit I'm quite an idiot. So please bear with me.

My game dies upon initialization. 8O I've stepped through with the debugger, trying to figure out where the problem is. I believe I've isolated the problem, because I ripped out two Classes which control the level and current map, and the header containing the level data. Once that was done, the game initialized and displayed the main menu.

My level data is broken up into several multidimensional arrays.

Code:

static map_ent_t levelOneObjects[ROOMS_PER_LEVEL][MAX_OBJECTS_PER_ROOM];
static BOOL levelOneTiles[ROOMS_PER_LEVEL][ROWS_PER_ROOM][COLS_PER_ROOM];


To get an idea, there are 16 rooms per level. Tiles are 16x16, and rooms are 320x240 in size. This means 300 tiles per room. 4800 tiles per map.

The current set up for objects is 4 max per level, and 16 rooms (obviously). This comes to 64 objects per level.

The map_ent_t struct is as follows:

Code:

typedef struct tagMAPENT
{
// r/c = Row/Col of the tile to spawn on.
tagMAPENT(DWORD cloneID, DWORD r, DWORD c)
{
this->CloneID = cloneID;
this->SpawnTile.x = c;
this->SpawnTile.y = r;
}

DWORD CloneID;
POINT SpawnTile;
} map_ent_t;


This information is global data (I currently have yet to implement loading level data from a file).

Now here's where my ignorance comes into play. Is this data pushed on to the stack? If it is, then this would explain why my game blows up on initialization. And it also begs the question: is it going to be possible to hold game data like this within my application, or am I going to have to create a level loader and load the data from the file?

This also brings me to another problem. My Level class holds data very similarly. It has multidimensional arrays almost identical to the above (except they hold more information, because it actually creates the data and holds a tile_t). Should I change this so it dynamically allocated the array and holds the information in memory (the heap)? Will this also solve part of my problem?

Thanks for the help! :D

EDIT:
I've included the leveldata.h file (so you can see the actual code for it).

Also, here's the Level class:

Code:

class Level
{
public:

Level();
~Level();

void Load(DWORD bgIDs[], BOOL tiles[][ROOM_TILE_ROWS][ROOM_TILE_COLS], map_ent_t objects[][MAX_OBJECTS_PER_ROOM], map_ent_t player);
void Unload();

void LoadRoom(DWORD roomID);

private:

entity_t* LoadEntity(const map_ent_t& mapEnt, DWORD room);

DWORD m_bgIDs[ROOMS_PER_LEVEL];
tile_t m_tiles[ROOMS_PER_LEVEL][ROOM_TILE_ROWS][ROOM_TILE_COLS];
entity_list_t m_objects[ROOMS_PER_LEVEL];
entity_t* m_pPlayer;

};
Attachments:
leveldata.h (37 KB)
Have you increased the stack size in the linker settings? It will <i>not</i> automatically determine what size stack your app needs.

Project->Settings->Link Tab->Output Category
Increase the Reserve and Commit values.

Dan East
Pejo Software - Per · 11 Feb 2005, 20:56 UTC
Global data is not the same as stack data.
A suggestion: let the linker generate a map file and you will se where your data will be (this will not help you with your stack problem though).
I love you guys!

I followed Dan Easts suggestion, and now the application works (I increased the values to max). Obviously, though, if I add any more levels it'll more than likely blow up again.

So this brings me to the fundamental question of: what's the best way to handle gobs and gobs of data?

Should I dynamically allocate the 3 dimensional array of tiles in my Level class (probably use a vector< vector< vector<tile_t> > > and .reserve() the space?), and load the level data from a seperate file so I don't have these huge arrays in global data?

Like I said I'm not familiar with the whole memory stuff (I know there's a heap and a stack, and dynamically allocated memory goes on the heap.. but that's about it), so if someone would be so kind enough to explain OR have a link to a tutorial, I'd be grateful.

Pejo Software:
Where's the option for the "generate a map file?" I'm using eVC 4.0.

EDIT:

Since dynamically allocating a 3 dim array is ugly, someone suggested the method below. I just thought I'd share since I found it quite ingenious.

Code:

struct avect { A a[32][25][128]; };
avect * x = new avect( ); //on the heap!