Sign in to follow this  
NickGravelyn

Run Time Error In xtree.h

Recommended Posts

I just tried getting my scene graph working, but I'm getting a strange error involving my use of either the std::vector or std::map structures. Here's the error:
Run-Time Check Failure #2 - Stack around the variable '_Lk' was corrupted.
I haven't a clue where to start to fix this. I know approximately where it happens. It happens during a constructor for one of my classes. Weird thing is that there is nothing in the constructor. I don't understand it. However, the class does contain seven std::map structures so that could be it, though I'm not sure why it'd crash like this. Any ideas? Edit: I've narrowed it down. I get this error seven times, once per std::map object. Here's what my maps look like:
		map<D3DXHANDLE, bool>				boolList;
		map<D3DXHANDLE, float>				floatList;
		map<D3DXHANDLE, int>				intList;
		map<D3DXHANDLE, D3DXMATRIX>			matrixList;
		map<D3DXHANDLE, LPCSTR>				stringList;
		map<D3DXHANDLE, IDirect3DTexture9*>	textureList;
		map<D3DXHANDLE, D3DXVECTOR4>		vectorList;
Any ideas what's causing the problem? It happens when the std::maps are in their constructor.

Share this post


Link to post
Share on other sites
You'll have to show us some code. My guess is that somthing goes wrong in the constructor of one of your class's members.

Edit:
Hehe didn't catch your edit. One thing to make sure of is that this code runs after D3D is initialized. I don't know DX, so that's all I could say.

Share this post


Link to post
Share on other sites
It does run after DirectX is initialized, but that shouldn't have any effect on working or not. This seems like I'm causing an error in the constructor of the std::map itself.

Edit:
I take that back. The error is in the class _Tree in the method Init(). Here's a few lines of what's there:
 void _Init()
{_Nodeptr _Tmp = _Buynode(0, _Black);
{_Lockit _Lk;
if (_Nil == 0)
{_Nil = _Tmp;
_Tmp = 0;
_Left(_Nil) = 0, _Right(_Nil) = 0; }
++_Nilrefs; }
if (_Tmp != 0)
_Freenode(_Tmp);
_Head = _Buynode(_Nil, _Red), _Size = 0;
_Lmost() = _Head, _Rmost() = _Head; } //my error is on this line
iterator _Insert(_Nodeptr _X, _Nodeptr _Y, const _Ty& _V)
{_Nodeptr _Z = _Buynode(_Y, _Red);
_Left(_Z) = _Nil, _Right(_Z) = _Nil;
_Consval(&_Value(_Z), _V);
++_Size;
if (_Y == _Head || _X != _Nil
...

Share this post


Link to post
Share on other sites
Try putting a DWORD value before those map structures, and set it to some known value (0xcafebabe or something) some point before these errors pop up. Then set a variable watch to trigger a breakpoint whenever it changes (Assuming MSVC).
That'll tell you when it's changed, and you can use the call stack to find out where the buffer overflow is (Since that's almost certainly what it is).

What compiler / IDE are you using?

Share this post


Link to post
Share on other sites
Yeah, the actual problem isn't there; Steve is right, it's probably a buffer overflow. The problem won't be in the _Tree class, as that's a private portion of STL. Show us the constructor code for that class.

Share this post


Link to post
Share on other sites
I'm using Visual C++ 2005 Express.

Here's the mighty constructor for the class:
SGEffectParametersNode::SGEffectParametersNode(void)
{
}



There's nothing there. I'm also confused what Evil Steve meant with his post. Can you explain that a bit more? What is a buffer overflow?

Share this post


Link to post
Share on other sites
You are probably writing past the bounds of an array somewhere and corrupting the stack. Show the code around the creation of that object. Do you use std::string or char *'s? std::vector or C arrays?

Share this post


Link to post
Share on other sites
Add another DWORD (or unsigned int) member varible to your class, and stick it before the maps. Then goto Debug -> New Breakpoint -> New Data Breakpoint, and enter &m_dwValue (or whatever the DWORD member is called) for the address, and 4 for the size. (This is assuming VS2005, other versions will be similar)

Now MSVC will break when that data changes - which is when your stack gets corrupted. You can then use call stack to find what call changed the memory.

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