Problem with Declaring a D3DCOLOR array, Too many Variables?

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
nitsu121
Posts: 1
Joined: March 21st, 2013, 12:14 am

Problem with Declaring a D3DCOLOR array, Too many Variables?

Post by nitsu121 » May 20th, 2013, 5:33 pm

Fellow programmers I humbly request assistance.

I am working on a game and everything is working fine, I have several sprites and several D3DCOLOR surfaces declared that I am using to show various imags with no issue. I then tried to add another D3DCOLOR array " D3DCOLOR milared[ 260 * 117 ];". This builds fine. However, when I run it, it crashes with "Unhandled exception at 0x771715de in Chili DirectX Framework.exe: 0xC00000FD: Stack Overflow." At which point it breaks at the if(retval == 0) line in the free.c file. The code that I am using is below. The last line in the code is D3DCOLOR milared[ 260 * 401 ]; and it is currently commented out. If I comment it, it works fine. When I uncomment it I get the problem described above. I am wondering if there can be too many variables defined? Any help will be appreciated.

#pragma once
#include "D3DGraphics.h"
#include "Keyboard.h"
#define ncake 3
#define DUDEWIDTH 50
#define DUDEHEIGHT 80
#define DUDENFRAMES 14
#define DUDEFRAMETIME (45/DUDENFRAMES)
#define DUDEKEYCOLOR D3DCOLOR_XRGB(255,255,255)
#define DUDEFILENAME "WalkinDude\\wdude"
#define DUDESPEED 1.5f
#define NDUDES 60
#define condwidth 30
#define condheight 49

class Game
{
public:
struct cake
{
float xvel;
float yvel;
float xpos;
float ypos;
int size;
int r;
int g;
int b;
bool alive;
};
public:
Game( HWND hWnd,const KeyboardServer& kServer );
void Go();
private:
void ComposeFrame();
cake cake[ncake];
void calcs();
bool circlecoltest(float xa, float ya, float rada, float xb, float yb, float radb );
void trioffscreentest(float* yvel,float* xvel,float* ytlc,float* xtlc,float* sidelength,int index);
void sqroffscreentest(float* yvel,float* xvel,float* ytlc,float* xtlc,float* sidelength,int index);
void ciroffscreentest(float* yvel,float* xvel,float* y,float* x,float* rad,int index);
void updateSp(Sprite* sprite);
void updateCo(Sprite* sprite);
void updateEgg(Sprite* sprite);
void spOffscreentest(Sprite* sprite);
void eggOffscreentest(Sprite* eggSprite);
void condOffscreentest(Sprite* sprite);
int SpInConTest( Sprite* spSprite, Sprite* condSprite );
int SpInEggTest( Sprite* eggSprite, Sprite* spSprite );
int levelselect(int level);
void numbertextplacer(int x, int y, float number, D3DCOLOR color);
void countertext();
void textcalc();
void initSp(Sprite* spSprite);
void initEgg(Sprite* eggSprite);
void intiCond(Sprite* condSprite);
void resetDeadSp(Sprite* spSprite);
void unLoadCond(Sprite* condSprite);
void automover();
void level1();
void draw();
private:
KeyboardClient kbd;
D3DCOLOR surface[ 50 * 80 ];
D3DGraphics gfx;
D3DCOLOR dudeSurfaces[ DUDEHEIGHT * DUDEWIDTH * DUDENFRAMES ];
D3DCOLOR condSurface0[ 30 * 49 ];
D3DCOLOR condSurface1[ 30 * 49 ];
D3DCOLOR condSurface2[ 30 * 49 ];
D3DCOLOR condSurface3[ 30 * 49 ];
D3DCOLOR condSurface4[ 30 * 49 ];
D3DCOLOR condSurface5[ 32 * 49 ];
D3DCOLOR condSurface6[ 34 * 49 ];
D3DCOLOR condSurface7[ 36 * 49 ];
D3DCOLOR condSurface8[ 38 * 53 ];
D3DCOLOR condSurface9[ 46 * 51 ];
D3DCOLOR condSurface10[ 42 * 104 ];
D3DCOLOR eggSurface[ 52 * 52 ];
D3DCOLOR spSurface[ 61 * 11 ];
D3DCOLOR gameoversurface[ 257 * 387 ];
Sprite dudeSprites[ DUDENFRAMES ];
Sprite condSprite[ 11 ];
Sprite spSprite[ncake];
Sprite eggSprite;
Sprite gameoversprite;
D3DCOLOR fontSurf[ 512 *84 ];
Font fixedSys;
int frameNumber;


//D3DCOLOR milared[ 260 * 401 ];
};

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Problem with Declaring a D3DCOLOR array, Too many Variab

Post by LuX » May 20th, 2013, 6:36 pm

Yeah, you ran out of memory. But no worries: in one of the lessons you will learn to allocate memory and that will solve the problem.

The "stack" is basically a small amount of memory reserved for your program, but it shouldn't be used to store huge images and stuff, as will be taught later.
ʕ •ᴥ•ʔ

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Problem with Declaring a D3DCOLOR array, Too many Variab

Post by albinopapa » May 22nd, 2013, 3:59 am

LuX is right, somewhere in the late teens or early 20's of the beginner series chili goes over dynamic memory allocation where you get to access the rest of the memory on your computer. You can look up "malloc" or "new []" on http://www.cplusplus.com for a heads up or just wait.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply