程序运行完毕出现 Run-Time Check Failure

这几天一直被这个问题所困,代码如下

int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR lpCmdLine,int nCmdShow)
{

YGEGame Game;

YGEAppParam AppParam;
AppParam.hInstance = hInst;
AppParam.pApplication = &Game;
AppParam.hPrevInst = hPrevInst;
AppParam.bWindowed = true;
AppParam.bMulti = false;
AppParam.bShowMouse = true;
AppParam.uScreenHeight = 600;
AppParam.uScreenWidth = 800;
_tcsncpy_s( AppParam.szAppName, (TCHAR*)”Sample”, DEFAULT_TITLE_NAME_LEN );
_tcsncpy_s( AppParam.szWndTitleName, (TCHAR*)”This is Only a Sample :)”, DEFAULT_TITLE_NAME_LEN );

YGEAppFrame App;
if( App.CreateApplication( AppParam ) )
{
App.RunApplication( );
}
return 0;
}

每次运行到return 0 之后,就会弹出消息:

Run-Time Check Failure #2 - Stack around the variable ‘App’ was corrupted.

原因很清楚,App附近的退栈已被损坏,但是由什么导致的不得而知,如果不加宏USE_CEGUI则一切正常,开始是怀疑是Adapter里头有内存越界,但是看了看没有,是个很简单的类,于是怀疑是Frame类的大小结构定义的问题。

其中YGEAppFrame定义如下:

class GAME_FRAME_API YGEAppFrame
{
public:

YGEAppFrame( );
~YGEAppFrame( ){ }

boolCreateApplication( YGEAppParam& AppParam );
boolRunApplication( void );
HWNDGetMainWindow( void ){ return m_wndMain; }

public:

private:

static LRESULT CALLBACK wndProc(HWND hWnd,UINT Message,WPARAM wParam,LPARAM lParam );

static voidmouseEnter( void );
static voidmouseLeave( void );
#ifdef USE_CEGUI
static UINT virtualKeyToScanCode( WPARAM wParam, LPARAM lParam );
static bool setIMEFollow( HWND hWnd );
static bool getFocusedInputBoxCoord( POINT& point, float& height );
static bool InjectUnicode( CEGUI::utf32 code_point );
#endif // USE_CEGUI

booldoWin32Event( bool& idle );
boolregisterWndClass( HINSTANCE hInst, LPCTSTR szAppName );

private:

/*************************************************************************
Static Member
*************************************************************************/
static boolms_bMouseInWindow;
static YGEApplication*ms_pApplication;

HWNDm_wndMain;
boolm_bFullScr;
DWORDm_dwCurTimeCount;
DWORDm_dwLastGameTimeCount;
DWORDm_dwLastRenderTimeCount;
TCHARm_szAppName[DEFAULT_TITLE_NAME_LEN];
TCHARm_szWndTitleName[DEFAULT_TITLE_NAME_LEN];

Idle3DEngine*m_p3DEngine;
#ifdef USE_CEGUI
YGECEGUIAdpater*m_pAdapter;
#endif // USE_CEGUI
};

在网上搜了很多文章,都没有找到究竟是什么原因,后来发现只要将USE_CEGUI这个宏约束从Adpater上去掉之后,就一切正常,看来头文件里头不能虽然对指针用宏来约束,哎,其实还是没弄懂到底是为什么

Tag 标签: 堆栈成员变量