简体   繁体   English

调用堆栈中的访问冲突

[英]Access Violation in call stack

I get this error: First-chance exception at 0x003f31b5 in Cts.exe: 0xC0000005: Access violation reading location 0xe1672514.我收到此错误:Cts.exe 中 0x003f31b5 处的第一次机会异常:0xC0000005:访问冲突读取位置 0xe1672514。

When I use the call stack, it spits out to this method.当我使用调用堆栈时,它会吐出到这个方法。 I commented which line specifically.我具体评论了哪一行。

When I click cancel from debugging when the program runs, the violation happens.当我在程序运行时从调试中单击取消时,就会发生违规。

At the bottom, I have included my Cancel method as well.在底部,我也包含了我的 Cancel 方法。

void CInpINS::OnTimer(UINT nIDEvent) 
{

  int i,j, totalbytes;
  bool bfilefnd = false;


  CConvb Convb;
  CString tmp;

  for (i = 0; i < (int) m_nNumMsgs; i++) {
      m_pBDF[i]->m_numrecs = m_pIDF[i]->m_numrecs;

      for (j = 0; j < MAXBYTECNT; j++) {
                OutBytes[j] = 0;
      }

        // set first 5 words 
      OutBytes[1] = m_nSelectedMsgNum[i];

      OutBytes[3] = (int)m_pIDF[i]->IDFFields[m_pIDF[i]->m_numrecs-1].ebyte/2+6; // THIS LINE SPECIFICALLY

      CConvb Convb;

      if (i == 0) m_dTimeofTransmission += m_nRate;
      tmp.Format("%20.0f",m_dTimeofTransmission);

      Convb.CONV_Timetag_to_Bytes(tmp, OutBytes[4], OutBytes[5],
                              OutBytes[6], OutBytes[7],
                              OutBytes[8], OutBytes[9],
                              OutBytes[10], OutBytes[11]);

        // start at 11 because byte 0 and 1 are input or output msg, then bytes 2 and 3 are word count
        // bytes 4 through 11 are gps time
        for (j = 0; j < m_pBDF[i]->m_numrecs; j++) {
            if ((j == 0)||(j == 1))  
            {
                Convb.ConvFld(tmp,
                    m_pIDF[i]->IDFFields[j].bbyte+9,
                    m_pIDF[i]->IDFFields[j].ebyte+9,
                    m_pIDF[i]->IDFFields[j].bbit,
                    m_pIDF[i]->IDFFields[j].ebit,
                    m_pIDF[i]->IDFFields[j].dtype,
                    m_pIDF[i]->IDFFields[j].Desc,OutBytes);

            }
            else
            {
                Convb.ConvFld(m_pBDF[i]->BDFFields[j],
                    m_pIDF[i]->IDFFields[j].bbyte+9,
                    m_pIDF[i]->IDFFields[j].ebyte+9,
                    m_pIDF[i]->IDFFields[j].bbit,
                    m_pIDF[i]->IDFFields[j].ebit,
                    m_pIDF[i]->IDFFields[j].dtype,
                    m_pIDF[i]->IDFFields[j].Desc,OutBytes);

            }
        }

        totalbytes = OutBytes[3];
        m_pDoc->sendmsg(totalbytes, false, OutBytes);
        tmp.Format("Sent Message");
        AddToListBox(tmp);
        UpdateData(false);
        m_nNumSent +=1;

}

}

Here is the cancel method:这是取消方法:

void CInpINS::OnCancel() 
    {
if (m_bSetIDF) 
{
    for (int i = 0; i < (int) m_nNumMsgs; i++) {
        delete m_pIDF[i];
        delete m_pIDFCustm[i];
        delete m_pBDF[i];   
    }
    m_bSetIDF = false;
}

AfxGetMainWnd()->PostMessage(WM_GOODBYEINPINS, IDOK);

CDialog::OnCancel();

}

This is coded in C++ Visual Studio 2010. I think there may be some NULL pointers or something but I am not sure.这是在 C++ Visual Studio 2010 中编码的。我认为可能有一些 NULL 指针或其他东西,但我不确定。 Any help would be appreciated.任何帮助,将不胜感激。 Thank you.谢谢你。

Your OnCancel is de-allocating memory without making sure that OnTimer isn't still accessing that memory.您的OnCancel正在取消分配内存,而没有确保OnTimer仍在访问该内存。

Make sure to call KillTimer (and ensure that OnTimer has finished) before deleting the variables.确保在删除变量之前调用KillTimer (并确保OnTimer已完成)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM