From: VT on
I recently ported an app from VC2003 to VC2005. My app now crashes on
exit. The following is the stack trace from the app.

mfc80d.dll!CThreadLocalObject::GetData(CNoTrackObject * (void)*
pfnCreateObject=0x78245650) Line 409 + 0x3 bytes C++


mfc80d.dll!CThreadLocal<AFX_MODULE_THREAD_STATE>::GetData() Line
177
+ 0xd bytes C++
mfc80d.dll!AfxGetModuleThreadState() Line 464 + 0x11 bytes C++
mfc80d.dll!AfxWinTerm() Line 47 + 0x5 bytes C++


mfc80d.dll!AfxWinMain(HINSTANCE__ * hInstance=0x00400000,
HINSTANCE__
* hPrevInstance=0x00000000, char * lpCmdLine=0x0015233a, int
nCmdShow=1) Line 62 C++


SzSimTool.exe!WinMain(HINSTANCE__ * hInstance=0x00400000,
HINSTANCE__
* hPrevInstance=0x00000000, char * lpCmdLine=0x0015233a, int
nCmdShow=1) Line 29 C++


SzSimTool.exe!__tmainCRTStartup() Line 578 + 0x35 bytes C
SzSimTool.exe!WinMainCRTStartup() Line 403 C
kernel32.dll!7c816fd7()
[Frames below may be incorrect and/or missing, no symbols loaded for
kernel32.dll]


It appears that AfxGetModuleThreadState() returns a seemingly valid
AFX_MODULE_THREAD_STATE* object.


However, the memory under it is inaccessible. So, when it gets to
the
GetData() call inside of the CThreadLocalObject, the this pointer is
pointing to memory it has no access to. Therefore, as soon as it
attempts
to execute if (m_nSlot == 0), it crashes with the following
exception:
Unhandled exception at 0x78246d10 (mfc80d.dll) in SzSimTool.exe:
0xC0000005: Access violation reading location 0x05878b48.


Anyone have any ideas as to what is causing this? If not how can I go
about debugging this problem.


Thanks,
V