CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2005

    Angry CRash in _AFX_CTL3D_THREAD::~_AFX_CTL3D_THREAD()

    When exiting my program it crashes here (mainly in the debug build).
    This is all MFC/CRT code so I don't have any control over it - unless there's some tidying up that's not done. I'm not sure about that as this is all supposed to be automatic. Using MFC6 as a static library in Win2000. Mainly legacy code too, so I'm struggling a bit.

    Code: From APP3DS.CPP in MFC/SRC

    _AFX_CTL3D_STATE* pCtl3dState = _afxCtl3dState.GetDataNA();
    if (pCtl3dState != NULL && pCtl3dState->m_pfnUnAutoSubclass != NULL)
    (*pCtl3dState->m_pfnUnAutoSubclass)(); // <--- crashes HERE

    All the functions in pCtl3dState are set to 0xfeeefeee. The program did originally call Enable3DControlsStatic but as that's obsolete I've taken it out but it made no difference.

    Last edited by simon.heffer; August 25th, 2005 at 03:29 AM. Reason: typo

  2. #2
    Join Date
    Apr 2013


    Sorry to resurrect such an old thread, but I wanted to document the solution for posterity... here's a workaround I added to a project where I was getting this crash due to freeing the the _afxCtl3dState object twice:

     // Need MFC source installed in order for our workaround to work!
     #include <../src/afximpl.h>
    Stick this code at the end of CWinApp::InitInstance() (for a modal dialog app) or at the end of CWinApp::ExitInstance() for a document/view app:

    	// Work around stupid MFC bug causing crash due to _afxCtl3dState being freed prematurely or without pointer getting set to NULL...grrr...
    	_AFX_CTL3D_STATE* pCtl3dState = _afxCtl3dState.GetDataNA();
    	delete pCtl3dState;
    	_afxCtl3dState.m_pObject = NULL;
    The workaround explicitly frees the _AFX_CTL3DSTATE object, then sets the CProcessLocal object's m_pObject to NULL so it won't try to free it again.

    Hope that helps somebody who's still using this old compiler (this worked on VC6 and may be required on later versions -- not sure if/when it's been fixed by MS).


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.