簡體   English   中英

調用堆棧中的訪問沖突

[英]Access Violation in call stack

我收到此錯誤:Cts.exe 中 0x003f31b5 處的第一次機會異常:0xC0000005:訪問沖突讀取位置 0xe1672514。

當我使用調用堆棧時,它會吐出到這個方法。 我具體評論了哪一行。

當我在程序運行時從調試中單擊取消時,就會發生違規。

在底部,我也包含了我的 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;

}

}

這是取消方法:

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();

}

這是在 C++ Visual Studio 2010 中編碼的。我認為可能有一些 NULL 指針或其他東西,但我不確定。 任何幫助,將不勝感激。 謝謝你。

您的OnCancel正在取消分配內存,而沒有確保OnTimer仍在訪問該內存。

確保在刪除變量之前調用KillTimer (並確保OnTimer已完成)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM