• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Calin

Stack overflow.

33 posts in this topic

Hi, I'm getting an *Unhandled exception at 0x00449647 in rtt.exe: 0xC00000FD: Stack overflow* and I dont know how to track it. Breaking shows a line in chkstk.asm. How do I figure out which line in my code is triggering the error. I can't step in/out of the code. The Call stack row before chkstk() Line 99 (ASM) is _tmainCRTStartup() Line 318 (C). The 318 line in main doest stand out in any way(nothing dangerous is happening at that line). As a side note why does VS mark C++ code as C
0

Share this post


Link to post
Share on other sites
Do you use any recursion in your code, i.e. functions calling themselves (directly or indirectly)?
0

Share this post


Link to post
Share on other sites
yes

[edit]
ok found the mistake thanks! My recusion brake wasn`t build propelry
0

Share this post


Link to post
Share on other sites
The call stack will also show your recursive calls, and you can use the debugger to find out why it's recursing so deep.
0

Share this post


Link to post
Share on other sites
void lights::MapChildren(int XParent, int YParent, int ParentInt, bool goN, bool goS, bool goE, bool goW, int Recursion)
{
if(Recursion < 20)
{
Recursion++;
MapChildren(x,y,Intensity, true, true, true, true,Recursion);
}
}


MapChildren(X,Z,220,true,true,true,true,0);




Actually it seems fine, dont see anything wrong with it.

Quote:
Original post by Evil Steve
The call stack will also show your recursive calls, and you can use the debugger to find out why it's recursing so deep.


There`s nothing else in the call stack
0

Share this post


Link to post
Share on other sites
You pass Recursion to your MapChildren call without modifying it. So if it's less than 20 to start with, it will always stay less than 20.
0

Share this post


Link to post
Share on other sites
Can you provide a minimal compiling example of the problem? If you don't have anything else in your call stack, that implies to me that the stack is corrupt, or you're trying to debug a release build.
0

Share this post


Link to post
Share on other sites
[img]http://proimpact2.googlepages.com/scr.jpg[/img]
that`s all the stack has

I commented out the recursion so it never gets called. That should stop it being the cause if it was. Im still getting the error though. P.S its a irrlicht wanna be game with more or less code in it, I have no clue what`s causing the error so I dont know how can I isolate the problem in a minimal example )
P.P.S being an irrlicht program it starts out as a console which then creates the window, however it breaks before any console is displayed.
0

Share this post


Link to post
Share on other sites
Sounds like you may have over run an array inside a function, which will screw up the return address and stack.
Or just written to a bad address.
Difficult to tell without seeing the code.
0

Share this post


Link to post
Share on other sites
It's also possible that you have a huge (1MB or so) array on the stack. What does your main() function look like?
0

Share this post


Link to post
Share on other sites
ok, here it is the programmers nightmare


int main()
{
// let user select driver type

video::E_DRIVER_TYPE driverType = video::EDT_DIRECT3D9;

printf("Please select the driver you want for this example:\n" " (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n" " (d) Software Renderer\n (e) Burning's Software Renderer\n" " (f) NullDevice\n (otherKey) exit\n\n");

char i;
std::cin &gt;&gt; i;

switch(i)
{
case 'a': driverType = video::EDT_DIRECT3D9;break;
case 'b': driverType = video::EDT_DIRECT3D8;break;
case 'c': driverType = video::EDT_OPENGL; break;
case 'd': driverType = video::EDT_SOFTWARE; break;
case 'e': driverType = video::EDT_BURNINGSVIDEO;break;
case 'f': driverType = video::EDT_NULL; break;
default: return 1;
}

// create device and exit if creation failed

IrrlichtDevice* _device =
createDevice(driverType, core::dimension2d&lt;s32&gt;(800, 800),
16, false, false);

if (_device == 0)
return 1; // could not create selected driver.

video::IVideoDriver* _driver = _device-&gt;getVideoDriver();
scene::ISceneManager* _smgr = _device-&gt;getSceneManager();
gui::IGUIEnvironment* _env = _device-&gt;getGUIEnvironment();



// add white light
_smgr-&gt;addLightSceneNode(0, core::vector3df(-15,5,-105),
video::SColorf(1.0f, 1.0f, 1.0f));

// set ambient light
_smgr-&gt;setAmbientLight(video::SColor(0,60,60,60));

/*
The next is just some standard stuff: Add a user controlled camera to
the scene, disable mouse cursor, and add a test cube and let it rotate
to make the scene more interesting.
*/


// add fps camera
irr::scene::ICameraSceneNode * _GameCamera = _smgr-&gt;addCameraSceneNode(0, core::vector3df(-100,0,100), core::vector3df(-100,0,0));

// disable mouse cursor
_device-&gt;getCursorControl()-&gt;setVisible(false);

// create test cube
scene::ISceneNode* _test = _smgr-&gt;addCubeSceneNode(160);
scene::ISceneNode* _unitlayer = _smgr-&gt;addCubeSceneNode(160);

// let the cube rotate and set some light settings
/*scene::ISceneNodeAnimator* anim = smgr-&gt;createRotationAnimator(
core::vector3df(0.3f, 0.3f,0));*/


_test-&gt;setPosition(core::vector3df(-100,0,-100));
_unitlayer-&gt;setPosition(core::vector3df(-100,0,-90));

_test-&gt;setMaterialFlag(video::EMF_LIGHTING, false); // disable dynamic lighting
_test-&gt;setMaterialFlag(video::EMF_ANISOTROPIC_FILTER, false);
_test-&gt;setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
_test-&gt;setMaterialFlag(video::EMF_TRILINEAR_FILTER, false);
_unitlayer-&gt;setMaterialFlag(video::EMF_LIGHTING, false);
_unitlayer-&gt;setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
/*node-&gt;setMaterialFlag(video::EMF_BILINEAR_FILTER, true);*/
/*test-&gt;addAnimator(anim);
anim-&gt;drop();*/


// set window caption
//_device-&gt;setWindowCaption(L"Irrlicht Engine - Render to Texture and Specular Highlights example");

/**********************************************
***********************************************
render texture
***********************************************/


// create render target
video::ITexture* _rt = _driver-&gt;addTexture(core::dimension2d&lt;s32&gt;(256,256), "RTT1",irr::video::ECOLOR_FORMAT::ECF_R8G8B8);
irr::video::ECOLOR_FORMAT F = _rt-&gt;getColorFormat();
video::ITexture* _rtulayer = _driver-&gt;addTexture(core::dimension2d&lt;s32&gt;(256,256), "RTT2",irr::video::ECOLOR_FORMAT::ECF_A8R8G8B8);

if (_driver-&gt;queryFeature(video::EVDF_RENDER_TO_TARGET))
{
_test-&gt;setMaterialTexture(0, _rt); // set material of cube to render target
_unitlayer-&gt;setMaterialTexture(0,_rtulayer);
}

/***********************************************
***********************************************
GUI

***********************************************/


irr::gui::IGUIWindow* _wnd = _env-&gt;addWindow(core::rect&lt;s32&gt;(0,600,800,800),
false, L"Console", 0, 5000);
//_wnd-&gt;setDraggable(false);


_wnd-&gt;setAlignment(irr::gui::EGUI_ALIGNMENT::EGUIA_CENTER,irr::gui::EGUI_ALIGNMENT::EGUIA_CENTER,irr::gui::EGUI_ALIGNMENT::EGUIA_CENTER,irr::gui::EGUI_ALIGNMENT::EGUIA_CENTER);
irr::gui::IGUIButton * _b1 = _env-&gt;addButton(core::rect&lt;s32&gt;(10,100,85,130), _wnd, GUI_ID_NEW_WINDOW_BUTTON, L"New Win");

irr::gui::IGUIButton * _m1 = _env-&gt;addButton(core::rect&lt;s32&gt;(20,150,60,170), _wnd, GUI_ID_NEW_WINDOW_BUTTON, L"North");
irr::gui::IGUIButton * _m2 = _env-&gt;addButton(core::rect&lt;s32&gt;(60,150,100,170), _wnd, GUI_ID_NEW_WINDOW_BUTTON, L"South");
irr::gui::IGUIButton * _m3 = _env-&gt;addButton(core::rect&lt;s32&gt;(100,150,140,170), _wnd, GUI_ID_NEW_WINDOW_BUTTON, L"East");
irr::gui::IGUIButton * _m4 = _env-&gt;addButton(core::rect&lt;s32&gt;(140,150,180,170), _wnd, GUI_ID_NEW_WINDOW_BUTTON, L"West");

irr::gui::IGUIButton * _r1 = _env-&gt;addButton(core::rect&lt;s32&gt;(20,70,40,90), _wnd, GUI_R1, L"1");
irr::gui::IGUIButton * _r2 = _env-&gt;addButton(core::rect&lt;s32&gt;(40,70,60,90), _wnd, GUI_R2, L"2");
irr::gui::IGUIButton * _d1 = _env-&gt;addButton(core::rect&lt;s32&gt;(60,120,120,140), _wnd, GUI_ID_NEW_WINDOW_BUTTON, L"Open");
irr::gui::IGUIButton * _d2 = _env-&gt;addButton(core::rect&lt;s32&gt;(120,120,180,140), _wnd, GUI_ID_NEW_WINDOW_BUTTON, L"Close");
irr::gui::IGUIButton * _r3 = _env-&gt;addButton(core::rect&lt;s32&gt;(60,70,80,90), _wnd, GUI_ID_NEW_WINDOW_BUTTON, L"3");
irr::gui::IGUIButton * _r4 = _env-&gt;addButton(core::rect&lt;s32&gt;(80,70,100,90), _wnd, GUI_ID_NEW_WINDOW_BUTTON, L"4");
irr::gui::IGUIButton * _r5 = _env-&gt;addButton(core::rect&lt;s32&gt;(100,70,120,90), _wnd, GUI_ID_NEW_WINDOW_BUTTON, L"5");
irr::gui::IGUIButton * _r6 = _env-&gt;addButton(core::rect&lt;s32&gt;(120,70,140,90), _wnd, GUI_ID_NEW_WINDOW_BUTTON, L"6");
irr::gui::IGUIButton * _r7 = _env-&gt;addButton(core::rect&lt;s32&gt;(140,70,160,90), _wnd, GUI_ID_NEW_WINDOW_BUTTON, L"7");
irr::gui::IGUIButton * _r8 = _env-&gt;addButton(core::rect&lt;s32&gt;(160,70,180,90), _wnd, GUI_ID_NEW_WINDOW_BUTTON, L"8");
irr::gui::IGUIButton * _r9 = _env-&gt;addButton(core::rect&lt;s32&gt;(180,70,200,90), _wnd, GUI_ID_NEW_WINDOW_BUTTON, L"7");
irr::gui::IGUIButton * _r10 = _env-&gt;addButton(core::rect&lt;s32&gt;(200,70,220,90), _wnd, GUI_ID_NEW_WINDOW_BUTTON, L"8");

irr::gui::IGUIListBox* _listbox =_env-&gt;addListBox(irr::core::rect&lt;s32&gt;(20, 30, 100, 60),_wnd);
_listbox-&gt;addItem(L"Test");

/*
_m1-&gt;setVisible(false);
_m2-&gt;setVisible(false);
_m3-&gt;setVisible(false);
_m4-&gt;setVisible(false);*/








// Map.AddRoom();
SAppContext context;
context._device = _device;
context._listbox = _listbox;
context.counter = 0;
context._b1 = _b1;
context._m1 = _m1;
context._m2 = _m2;
context._m3 = _m3;
context._m4 = _m4;
// Then create the event receiver, giving it that context structure.
MyEventReceiver receiver(context);
// And tell the device to use our custom event receiver.
_device-&gt;setEventReceiver(&receiver);

int lastFPS = -1;
int width = 256;
/***********************************************
***********************************************
Map and characters
***********************************************/

map Map;
Map.Tile(6);
Map.Room(0,2,2,4,4,0,0,2,0);
Map.Room(1,6,2,4,4,0,1,3,2);
Map.Room(2,9,2,2,4,0,0,3,3);
Map.Room(3,11,2,2,4,1,1,1,3);
Map.Room(4,2,6,4,4,0,0,1,0);
Map.Room(5,6,6,4,4,1,0,1,1);
Map.Room(6,10,7,4,6,1,0,0,1);


lights Lights;

chars Chars;
Chars.Character(50000,20000,4000,4000,Lights,20);
Chars.Character(50000,40000,4000,4000,Lights,20);
Chars.Character(40000,20000,4000,4000,Lights,20);



tcounter Timer;
__int64 MSElapsed =0;
__int64 MSFreq =0;
__int64 MSElapsedSinceStart =0;



int color1d = 256;
int color2d = 65536;
int color3d = 16777216;
while(_device-&gt;run())
if (_device-&gt;isWindowActive())
{
Timer.Loop(MSElapsed,MSElapsedSinceStart,MSFreq);

Chars.Logic((int)MSElapsed);


core::stringw str;
//str = L"0";
//Chars.Left(0,Map);
if(receiver.IsKeyDown(irr::KEY_LEFT))
{
Chars.Left(0,Map,Lights);
}
if(receiver.IsKeyDown(irr::KEY_RIGHT))
{
Chars.Right(0,Map,Lights);
}
if(receiver.IsKeyDown(irr::KEY_UP))
{
Chars.North(0,Map,Lights);
}
if(receiver.IsKeyDown(irr::KEY_DOWN))
{
Chars.South(0,Map,Lights);
}


_driver-&gt;beginScene(true, true, irr::video::SColor(0,200,200,200));

if (_rt)
{
s32* p = (s32*)_rt-&gt;lock ();




for(int i =0; i &lt; Map.RoomCount; i++)
{
for(int z =Map.Rooms[i].NWy*Map.TileSize; z &lt; Map.Rooms[i].SEy*Map.TileSize; z++)
{
for(int x =Map.Rooms[i].NWx*Map.TileSize; x &lt; Map.Rooms[i].SEx*Map.TileSize; x++)
{
p[z * width + x] = 0*color2d + (255/(i+1))*color1d + 0;
}
}
}

for(int z = 0; z &lt; Map.Pixels; z++)
{
for(int x =0; x &lt; Map.Pixels; x++)
{
if(Map.WallMap[z][x])
{
p[z * width + x] = 255*color2d + 255*color1d + 255;
}
}
}

for(int i =0; i &lt; Chars.CrCount; i++)
{
for(int z =Chars.Creatures[i].NWy/1000; z &lt; Chars.Creatures[i].SEy/1000; z++)
{
for(int x =Chars.Creatures[i].NWx/1000; x &lt; Chars.Creatures[i].SEx/1000; x++)
{
p[z * width + x] = 0*color2d + 0*color1d + (255/(i+1));
}
}
}



_rt-&gt;unlock();
_test-&gt;setVisible(true);
_smgr-&gt;setActiveCamera(_GameCamera);
}

if(_rtulayer)
{
s32* p = (s32*)_rtulayer-&gt;lock();



for(int z =0; z &lt; width; z++)
{
for(int x =0; x &lt; width; x++)
{
p[z * width + x] =
Lights.LightMap[z][x].a*color3d +
Lights.LightMap[z][x].r *color2d +
Lights.LightMap[z][x].g*color1d +
Lights.LightMap[z][x].b;
}
}


/*for(int i =0; i &lt; Chars.CrCount; i++)
{
for(int z =Chars.Creatures[i].NWy; z &lt; Chars.Creatures[i].SEy; z++)
{
for(int x =Chars.Creatures[i].NWx; x &lt; Chars.Creatures[i].SEx; x++)
{
p[z * width + x] = 100*color3d + 0*color2d + 0*color1d + (255/(i+1));
}
}
} */

_rtulayer-&gt;unlock();
}


// draw scene normally
_smgr-&gt;drawAll();
_env-&gt;drawAll();


core::position2d&lt;s32&gt; m = _device-&gt;getCursorControl()-&gt;getPosition();
_driver-&gt;draw2DRectangle(video::SColor(100,255,255,255),
core::rect&lt;s32&gt;(m.X-5, m.Y-5, m.X+5, m.Y+5));

_driver-&gt;endScene();

// display frames per second in window title
int fps = _driver-&gt;getFPS();
if (lastFPS != fps)
{
/*core::stringw str;*/
/*if(F == irr::video::ECOLOR_FORMAT::ECF_R5G6B5)
str = L"ECF_R5G6B5 - Render to Texture and Specular Highlights example";
if(F == irr::video::ECOLOR_FORMAT::ECF_R8G8B8)
str = L"ECF_R8G8B8 - Render to Texture and Specular Highlights example";
if(F == irr::video::ECOLOR_FORMAT::ECF_A1R5G5B5)
str = L"ECF_A1R5G5B5 - Render to Texture and Specular Highlights example";
if(F == irr::video::ECOLOR_FORMAT::ECF_A8R8G8B8)
str = L"ECF_A8R8G8B8 - Render to Texture and Specular Highlights example";*/

str += " ms: ";
str += (int)MSElapsed;
str += " FPS:";
str += fps;

_device-&gt;setWindowCaption(str.c_str());
lastFPS = fps;
}
}

_device-&gt;drop(); // drop device
return 0;
}

/*
**/



0

Share this post


Link to post
Share on other sites
For those that value their eyes, could you replace the quote with source tags, please?
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Calin

map Map;
Map.Tile(6);
Map.Room(0,2,2,4,4,0,0,2,0);
Map.Room(1,6,2,4,4,0,1,3,2);
Map.Room(2,9,2,2,4,0,0,3,3);
Map.Room(3,11,2,2,4,1,1,1,3);
Map.Room(4,2,6,4,4,0,0,1,0);
Map.Room(5,6,6,4,4,1,0,1,1);
Map.Room(6,10,7,4,6,1,0,0,1);




At a guess, Map.Tile(6) creates 6 tiles, and you are adding 7.
0

Share this post


Link to post
Share on other sites
Quote:
At a guess, Map.Tile(6) creates 6 tiles, and you are adding 7.

-no thats the width of a tile in pixels, arguments 2 and 3 in Room() are used to tell the number of tiles )
0

Share this post


Link to post
Share on other sites
What line in main() does the debugger point to when you get that exception?
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Calin
It brings the asm file right away
Ah, I didn't realise it's happening before you even get into main()...

One thing I could suggest is commenting out bits of code until the bug goes away, then you'll be able to track down what caused the bug (It'll be the last bit you commented out). That, and adding some printf() / cout lines will let you see if it's even getting into main().

It's also possible that you just have a crapload of data on the stack in main() - in which case you need to switch to allocating some data elsewhere (I.e. on the heap).
0

Share this post


Link to post
Share on other sites
Quote:
data on the stack in main() - in which case you need to switch to allocating some data elsewhere (I.e. on the heap)


what do you mean, can someone detail this a bit.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Calin
Quote:
data on the stack in main() - in which case you need to switch to allocating some data elsewhere (I.e. on the heap)


what do you mean, can someone detail this a bit.
Every local variable takes up some stack space (And every member variable in every class you have instanced as a local variable). On Windows by default you have 1MB of stack. If all of your local variables total more than 1MB, you'll get a stack overflow.

Try commenting out the code from the "Map and characters" comment to the end of main(). If the problem goes away, you know it's in there somewhere.

I'd hazard a guess that your Map class (or one of your other ones) has a crapload of member variables.
0

Share this post


Link to post
Share on other sites
I got the code to run by switching out several lines. The light class is making the trouble. [edit] found this thread googling chkstk.asm
http://www.gamedev.net/community/forums/topic.asp?topic_id=296695

Quote:
Original post by LessBreadchkstk (check stack) is a compiler intrinsic function that "touches" stack pages to ensure they are paged in before they are used. On Windows, the default size of the stack is 1 mb, but all of that memory is not paged in at the outset. The compiler inlines the chkstk function when it encounters stack variables (ie local function variables) larger than one page. eg array[128][128]. If that was an array of char, it would require 16kb or 4 pages (1 page == 4096 bytes). With a name like vertices, I suspect the size of each element of the array is a lot more than one byte. At any rate, chkstk, advances the stack pointer page by page, "touching" each page as it proceed through a loop counting down the number of pages the variable requires. It makes sense that the stack overflow exception lands in chkstk, because the "touching" instruction produces the fault when the stack pointer has gone beyond the stack limit.


I have an array of 256x256
color LightMap[256][256]; (each color has 4 ints) Is this is too big how do I solve it?

[Edited by - Calin on July 31, 2009 1:17:43 PM]
0

Share this post


Link to post
Share on other sites
Quote:
I have an array of 256x256
color LightMap[256][256]; (each color has 4 ints) Is this is too big how do I solve it?


I don't think the array is that big, it should be able to fit on the stack. But you could try allocating it on the heap to be sure, just make sure you 'delete[]' it after using it.
0

Share this post


Link to post
Share on other sites
Quote:

I don't think the array is that big, it should be able to fit on the stack. But you could try allocating it on the heap to be sure, just make sure you 'delete[]' it after using it.


How do you allocate on heap?

int *blah = new int[4][4];
delete [] blah;
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0