Stack Issues
by Mike Kuklinski · in Torque Game Engine Advanced · 04/22/2006 (3:19 pm) · 4 replies
I am getting a series of stack errors in this file during debug, right when the game is started. They prevent me from debugging, and disabling them crashes the app completely.
They are 'Stack around the variable blahblah was corrupted.' errors.
Most of the errors are occuring in the
'string DXDiagNVUtil::lpcwstrToString( const LPCWSTR in_lpcwstr )'
function.
Any idea what might be wrong?
The below is '/engine/gfx/D3D/DXDiagNVUtil.cpp'. (just that function, because the file is too large to post in it's entirety.)
string DXDiagNVUtil::lpcwstrToString( const LPCWSTR in_lpcwstr )
{
//@ consider using windows.h WideCharToMultiByte(..)
char * mbBuf;
size_t sz;
sz = 2 * wcslen( in_lpcwstr );
mbBuf = new char[sz];
wcstombs( mbBuf, in_lpcwstr, sz ); // convert the string
string outstr;
outstr = mbBuf;
SAFE_ARRAY_DELETE( mbBuf );
return( outstr );
}
It usually gives me the stack error on the return with outstr.
They are 'Stack around the variable blahblah was corrupted.' errors.
Most of the errors are occuring in the
'string DXDiagNVUtil::lpcwstrToString( const LPCWSTR in_lpcwstr )'
function.
Any idea what might be wrong?
The below is '/engine/gfx/D3D/DXDiagNVUtil.cpp'. (just that function, because the file is too large to post in it's entirety.)
string DXDiagNVUtil::lpcwstrToString( const LPCWSTR in_lpcwstr )
{
//@ consider using windows.h WideCharToMultiByte(..)
char * mbBuf;
size_t sz;
sz = 2 * wcslen( in_lpcwstr );
mbBuf = new char[sz];
wcstombs( mbBuf, in_lpcwstr, sz ); // convert the string
string outstr;
outstr = mbBuf;
SAFE_ARRAY_DELETE( mbBuf );
return( outstr );
}
It usually gives me the stack error on the return with outstr.
About the author
http://dev.stackheap.com/
#2
To expand:
In actuality, anywhere in that entire file where a string is declared, I get a stack corruption error.
For instance, if I blank that function and have it return "0", this function breaks:
I am using Visual C++ 2005 Express.
05/07/2006 (9:54 pm)
Most definately NOT fixed for me in MS3.To expand:
Run-Time Check Failure #2 - Stack around the variable 'outstr' was corrupted
string DXDiagNVUtil::lpcwstrToString( const LPCWSTR in_lpcwstr )
{
//@ consider using windows.h WideCharToMultiByte(..)
char * mbBuf;
size_t sz;
sz = 2 * wcslen( in_lpcwstr );
mbBuf = new char[sz+1];
wcstombs( mbBuf, in_lpcwstr, sz+1 ); // convert the string
string outstr;
outstr = mbBuf;
SAFE_ARRAY_DELETE( mbBuf );
return( outstr );
}In actuality, anywhere in that entire file where a string is declared, I get a stack corruption error.
For instance, if I blank that function and have it return "0", this function breaks:
Run-Time Check Failure #2 - Stack around the variable 't' was corrupted
int hackWToI( wstring & in_wstring)
{
string t = DXDiagNVUtil::WStringToString(in_wstring);
return atoi(t.c_str());
}I am using Visual C++ 2005 Express.
#3
05/08/2006 (10:57 am)
Have you checked to see if the function is getting NULL passed to it? Might be a simple fix.
#4
05/08/2006 (11:10 am)
Nope, it is always getting a real string... the function that calls it does a null check already.
Torque Owner Jeremiah Fulbright