Hi, Mr Mike, I'm the chinese guy again..to your response of my last thread: you're very welcome:). We should thank you for your excellent work to help the beginners know the entire game development,That's really helpful:)
Today I found the bug as here mentioned.
That means the program has a heap corruption problem. I found the key code is here:
In function :CMessageBox::CMessageBox(std::wstring msg, std::wstring title, int buttonFlags)
we can found
m_UI.AddButton(..g_pApp->GetString(IDS_CONTINUE).c_str()... );
Use the string.c_str() should be very careful.Look at the function declaretion:
AddButton(...LPCWSTR strText..);
std::wstring GameCodeApp::GetString(const int nID);
when GetString().c_str() passed to AddButton() and after AddButton()'s field, the string is destroyed that means the c_str() pointer is deleted too. But the CMessageBox is still using it.
so that's the problem.
Again, I hope this would help the readers like me searching code problems in this forum.:)
Edit.. oops...I add the
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_CHECK_EVERY_1024_DF | _CRTDBG_CHECK_CRT_DF);
to the code, it detected another heap corruption..and I don't know why..
Today I found the bug as here mentioned.
That means the program has a heap corruption problem. I found the key code is here:
In function :CMessageBox::CMessageBox(std::wstring msg, std::wstring title, int buttonFlags)
we can found
m_UI.AddButton(..g_pApp->GetString(IDS_CONTINUE).c_str()... );
Use the string.c_str() should be very careful.Look at the function declaretion:
AddButton(...LPCWSTR strText..);
std::wstring GameCodeApp::GetString(const int nID);
when GetString().c_str() passed to AddButton() and after AddButton()'s field, the string is destroyed that means the c_str() pointer is deleted too. But the CMessageBox is still using it.
so that's the problem.
Again, I hope this would help the readers like me searching code problems in this forum.:)
Edit.. oops...I add the
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_CHECK_EVERY_1024_DF | _CRTDBG_CHECK_CRT_DF);
to the code, it detected another heap corruption..and I don't know why..
The post was edited 2 times, last by shallway ().