Jump to content

  • Log In with Google      Sign In   
  • Create Account


Stack overflow.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
33 replies to this topic

#1 Calin   Members   -  Reputation: 240

Like
0Likes
Like

Posted 31 July 2009 - 01:30 AM

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 ©. 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

Sponsor:

#2 DevFred   Members   -  Reputation: 836

Like
0Likes
Like

Posted 31 July 2009 - 01:39 AM

Do you use any recursion in your code, i.e. functions calling themselves (directly or indirectly)?

#3 Calin   Members   -  Reputation: 240

Like
0Likes
Like

Posted 31 July 2009 - 01:40 AM

yes

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

#4 DevFred   Members   -  Reputation: 836

Like
0Likes
Like

Posted 31 July 2009 - 01:47 AM

Post those functions.

#5 Evil Steve   Members   -  Reputation: 1959

Like
0Likes
Like

Posted 31 July 2009 - 01:50 AM

The call stack will also show your recursive calls, and you can use the debugger to find out why it's recursing so deep.

#6 Calin   Members   -  Reputation: 240

Like
0Likes
Like

Posted 31 July 2009 - 01:53 AM

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

#7 SiCrane   Moderators   -  Reputation: 9561

Like
0Likes
Like

Posted 31 July 2009 - 02:10 AM

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.


#8 Calin   Members   -  Reputation: 240

Like
0Likes
Like

Posted 31 July 2009 - 02:16 AM

won`t Recursion++ increase the value by 1 with every call?

#9 SiCrane   Moderators   -  Reputation: 9561

Like
0Likes
Like

Posted 31 July 2009 - 02:19 AM

Somehow I managed not to see that.

#10 Evil Steve   Members   -  Reputation: 1959

Like
0Likes
Like

Posted 31 July 2009 - 02:21 AM

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.

#11 Calin   Members   -  Reputation: 240

Like
0Likes
Like

Posted 31 July 2009 - 02:38 AM

Posted Image
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.

#12 RabidDog   Members   -  Reputation: 116

Like
0Likes
Like

Posted 31 July 2009 - 02:50 AM

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.

#13 Evil Steve   Members   -  Reputation: 1959

Like
0Likes
Like

Posted 31 July 2009 - 02:52 AM

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

#14 Calin   Members   -  Reputation: 240

Like
0Likes
Like

Posted 31 July 2009 - 03:09 AM

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;
}

/*
**/





#15 zdlr   Members   -  Reputation: 266

Like
0Likes
Like

Posted 31 July 2009 - 03:17 AM

For those that value their eyes, could you replace the quote with source tags, please?

#16 RabidDog   Members   -  Reputation: 116

Like
0Likes
Like

Posted 31 July 2009 - 03:18 AM

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.

#17 Calin   Members   -  Reputation: 240

Like
0Likes
Like

Posted 31 July 2009 - 03:28 AM

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 )

#18 Evil Steve   Members   -  Reputation: 1959

Like
0Likes
Like

Posted 31 July 2009 - 03:38 AM

What line in main() does the debugger point to when you get that exception?

#19 Calin   Members   -  Reputation: 240

Like
0Likes
Like

Posted 31 July 2009 - 03:46 AM

It brings the asm file right away

#20 Evil Steve   Members   -  Reputation: 1959

Like
0Likes
Like

Posted 31 July 2009 - 04:06 AM

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).




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS