I have an old 32-bit MFC application in C++ which was written with Visual Studio 2010. It ran without problems. Now I had to upgrade to Visual Studio 2017 and it crashes pretty often when I click on the treeview window. I have a dmp file and when I open it then I see that it crashes here:
BOOL CObject::IsKindOf(const CRuntimeClass* pClass) const
{
ENSURE(this != NULL);
// it better be in valid memory, at least for CObject size
ASSERT(AfxIsValidAddress(this, sizeof(CObject)));
// simple SI case
CRuntimeClass* pClassThis = GetRuntimeClass(); //---->HERE Crash
ENSURE(pClassThis);
return pClassThis->IsDerivedFrom(pClass);
}
When I go back the call list then I end here:
//m_pTheModel is initialized with NULL
if (bValidValue == true)
m_pTheModel = GetModel((WORD)lHint);
if (m_pTheModel == NULL || !AfxIsValidAddress(m_pTheModel, sizeof(m_pTheModel)))
{
lock.Unlock();
return;
}
try
{
if ((m_pTheModel->IsKindOf(RUNTIME_CLASS(CMyClassModel))))
...
}
catch (...)
{
}
m_pTheModel is not NULL but when I look at the values in the debugger, for some values the memory is not readable.
What could the problem be? With the old version of visual studio I didn't have this problem. I have only recompiled this project and I had to set the target operation system to Windows XP.
The error message is “The thread tried to read from or write to a virtual address for which it does not have the appropriate access.”
I also don't understand why I can't catch this access violation with my try-catch around this.
Update: I found the reason. It was a strcpy that overwrites my pointer.