Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8259281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:49:22+00:00 2026-06-08T02:49:22+00:00

I am getting a stack overflow error when I create an instance of my

  • 0

I am getting a stack overflow error when I create an instance of my Dungeon class. I feel like it is because my dungeon class creates an array of rooms and my rooms create an array of cells. My only question is I have done this before and never had this issue. So what am I doing wrong this time? Are my arrays too big? I can make my rooms array to a maximum of [5][3] but I would like to have it a [5][5] size room. Is this just impossible to do?

I understand that a stack overflow error is when you run out of memory on the stack but how do I know when I exit that stack and can start fresh again? Or when something gets taken off that stack?

Here is my code on how these 3 classes are setup (Dungeon.h):

#ifndef DUNGEON_H
#define DUNGEON_H

#include <stdlib.h>
#include <string>
#include "TextureHandler.h"
#include "Room.h"

using namespace std;

class Dungeon
{
public:
    Dungeon();
    ~Dungeon();

private:
    static const int MAX_RM_ROWS = 5;   //Maximum amount of rows of rooms we can have
    static const int MAX_RM_COLS = 5;   //Maximum amount of columns of rooms we can have
    Room rooms[5][5];

    int currentDungeon;                 //Stores the ID of the current dungeon we are in.
    int currentRoomRow;                 //Stores the row position in the room array for what room the player is in
    int currentRoomCol;                 //Stores the column position in the room array for what room the player is in
protected:

};

#endif

Room.h

#ifndef ROOM_H
#define ROOM_H

#include <stdlib.h>
#include "Cell.h"

using namespace std;

class Room
{

public:
    Room();
    ~Room();
    void draw();
    void setupCell(int row, int col, float x, float y, float width, float height, bool solid, vector<float> texCoords);
    int getMaxRows();
    int getMaxCols();
private:
    static const int MAX_ROWS = 30;
    static const int MAX_COLS = 50;
    Cell cells[MAX_ROWS][MAX_COLS];

protected:
};

#endif

Cell.h

 #ifndef CELL_H
    #define CELL_H

    #include <stdlib.h>
    #include <vector>
    #include "GL\freeglut.h"

    using namespace std;

    class Cell
    {
    public:
    Cell();
    ~Cell();
    void setup(float x, float y, float width, float height, bool solid, vector<float> texCoords);
    void draw();
    float getX();
    float getY();
    float getWidth();
    float getHeight();
    bool isSolid();
    private:
    float x;
    float y;
    float height;
    float width;
    bool solid;
    vector<float> texCoords;
    protected:

    };

    #endif
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T02:49:24+00:00Added an answer on June 8, 2026 at 2:49 am

    Your arrays are quite big. A single Dungeon weights about 3 * sizeof(int) + 5 * 5 * 30 * 50 * sizeof(Cell), which is probably somewhere around 1200000 bytes*, i.e., more than one megabyte. That might be a lot to put on the stack, especially if you put more than one.

    My suggestion is to get rid of all the limits and use std::vectors instead of arrays. That uses the heap for storage, solving your problem and giving you unlimited rooms**!


    * sizeof(Cell) is probably around 32: 16 bytes from four floats, one byte for a bool, and 12-16 bytes for a vector, plus padding to align to 4 bytes boundaries.

    ** Well, limited by the available memory, or the operating system.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting stack overflow errors when I'm trying to publish() a NetStream after close()ing
I figured when I started getting stack overflow it was time to come here
I am getting a stack overflow in one of the recursive functions i am
I'm getting stack traces like this: java.lang.NoClassDefFoundError: sun/reflect/GeneratedMethodAccessor1 at sun.reflect.GeneratedMethodAccessor1.<clinit>(Unknown Source) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
I am getting this error: integerMultiplication.rb:4:in `untMul': stack level too deep (SystemStackError) in this
I am getting this error in a program that creates several (hundreds of thousands)
I followed the thread in stack overflow to implemt this, but i am getting
I am getting a StackOverflow Error in this code: EDIT [XmlAttribute(ID)] public string ID
I am getting the following java stackoverflow error on a xml transformation in weblogic
When running a test using the Tornado AsyncHTTPTestCase I'm getting a stack trace that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.