title: Object pointer randomly points to 0x00000
body: <p>I'm running a Visual C++ MFC application in release mode.  I'm compiling everything using Visual Studio 2010.</p>
  
  <p>My app runs a mini CNC mill through USB VCP communication.</p>
  
  <p>I have a XML file that stores the app's settings.</p>
  
  <p>My problem is this: ocassionaly (and this is repeatable) the pointer to the tinyxml2::XMLDocument I'm using gets set to 0x000.</p>
  
  <p>Info:</p>
  
  <p>Occasionally, the XML file get written to while the mill is running.</p>
  
  <p>Before the error happens, the mill I'm running siezes for almost 30 seconds.</p>
  
  <p>I'm using mutex locks to make sure the xmldoc doesn't get written to file twice at once.</p>
  
  <p>The mutex locks are working, and the mutex error never occurs.  I know the mutex code isn't perfect, but that isn't the issue.  Honest.</p>
  
  <p>I never write to the xmldoc pointer except when the parent class is booting up.</p>
  
  <p>And then, all of a sudden, the xmlDoc pointer gets set to zero.</p>
  
  <p>Any thoughts anyone?</p>
  
  <p>Here is my saving code, although the problem may lie elsewhere:</p>
  
  <pre><code>void XMLSettings::SaveToXML()
  {
      HANDLE g_Mutex = CreateMutex( NULL, TRUE, "XMLSavingMutex");
      DWORD wait_success = WaitForSingleObject( g_Mutex, 30000L);
      if(wait_success == WAIT_OBJECT_0){
          CIsoProApp* pApp = (CIsoProApp*)AfxGetApp();
          if(PathFileExists(pApp-&gt;DrivePath + "IsoPro\\temp.xml"))
          {
              DeleteFile(pApp-&gt;DrivePath + "IsoPro\\temp.xml");
          }
  
          if(0==&amp;xmlDoc)
          {
              OutputDebugString("xmlDoc == NULL");
          }
  
          int errorcode = xmlDoc-&gt;SaveFile(pApp-&gt;DrivePath + "IsoPro\\temp.xml");
  
          if(errorcode != 0)
          {
              OutputDebugString("xmlDoc == errorcode");
          }
  
          if(0==&amp;xmlDoc)
          {
              OutputDebugString("xmlDoc == NULL2");
          }
  
          if(0==xmlDoc)
          {
              OutputDebugString("xmlDoc == NULL");
          }
  
          if(PathFileExists(pApp-&gt;DrivePath + "IsoPro\\Settings.xml"))
          {
              DeleteFile(pApp-&gt;DrivePath + "IsoPro\\Settings.xml");
          }
          MoveFile(pApp-&gt;DrivePath + "IsoPro\\temp.xml",pApp-&gt;DrivePath + "IsoPro\\Settings.xml");
          ReleaseMutex(g_Mutex);
      }
      else
      {
          int errorInt = GetLastError();
          CString error;
          error.Format("%d",errorInt);
          if(errorInt != ERROR_ALREADY_EXISTS)
          {
              AfxMessageBox("XMLSavingMutex Error.  WaitSuccess = " + wait_success);
              AfxMessageBox("XMLSavingMutex Error.  GetLastError = " + error);
          }
      }
      CloseHandle(g_Mutex);
  }
  </code></pre>