程序运行完毕出现 Run-Time Check Failure #2 – Stack around the variable ‘App’ was corrupted.

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

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( ){ }

	bool		CreateApplication	( YGEAppParam& AppParam );
	bool		RunApplication		( void );
	HWND		GetMainWindow		( void ){ return m_wndMain; }

public:
	
private:

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

	static void	mouseEnter( void );
	static void	mouseLeave( 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

	bool	doWin32Event( bool& idle );
	bool	registerWndClass( HINSTANCE hInst, LPCTSTR szAppName );

private:

	/*************************************************************************
		Static Member
	*************************************************************************/
	static bool		ms_bMouseInWindow;
	static YGEApplication*	ms_pApplication;

	HWND	m_wndMain;
	bool	m_bFullScr;
	DWORD	m_dwCurTimeCount;
	DWORD	m_dwLastGameTimeCount;
	DWORD	m_dwLastRenderTimeCount;
	TCHAR	m_szAppName[DEFAULT_TITLE_NAME_LEN];
	TCHAR	m_szWndTitleName[DEFAULT_TITLE_NAME_LEN];

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

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

 

Tag 标签:

发表评论

电子邮件地址不会被公开。