簡體   English   中英

。訪問沖突讀取位置

[英].Access violation reading location

我遇到了一個非常奇怪的問題。

代碼如下:

::boost::shared_ptr<CQImageFileInfo> pInfo=CQUserViewDataManager::GetInstance()->GetImageFileInfo(nIndex); 
Image* pImage=pInfo->m_pThumbnail;
if(pImage==NULL)
    pImage=m_pStretchedDefaultThumbImage;
else
{
    //
    int sourceWidth  = pInfo->GetWidth();
    int sourceHeight = pInfo->GetHeight();

    int destX = 0,
        destY = 0; 

    float nPercent  = 0;
    float nPercentW = ((float)GetThumbImageWidth()/(float)sourceWidth);;
    float nPercentH = ((float)GetThumbImageHeight()/(float)sourceHeight);

    if(nPercentH < nPercentW)
    {
        nPercent = nPercentH;
        destX    = (int)((GetThumbImageWidth() - (sourceWidth * nPercent))/2);
    }
    else
    {
        nPercent = nPercentW;
        destY    = (int)((GetThumbImageHeight() - (sourceHeight * nPercent))/2);
    }

    int destWidth  = (int)(sourceWidth * nPercent);
    int destHeight = (int)(sourceHeight * nPercent);
    rcShowImage=CRect(rc.left+destX, rc.top+destY,rc.left+destX+destWidth,rc.top+destY+destHeight);
}
ASSERT(pImage != NULL); // passed assertion...
graphics.DrawImage(pImage,rcShowImage.left,rcShowImage.top,
rcShowImage.Width(),rcShowImage.Height()); // problem happened here.

我收到以下異常:

First-chance exception at 0x004095b0 in ec.exe: 0xC0000005: Access violation reading location 0xfeeefef2.
Unhandled exception at 0x004095b0 in ec.exe: 0xC0000005: Access violation reading location 0xfeeefef2.

我已經檢查了pImage ,我確定在調用graphics.DrawImage時,它不是NULL

  • 為什么會發生這樣的問題?
  • 什么是0xfeeefef2

0xfeeefeee是Windows堆(不是C運行時堆)的調試版本用於未初始化內存的填充模式。 0xfeeefef20xfeeefeee+4 聽起來您正在取消引用位於堆中分配的內存塊中(或從中復制)的未初始化指針。

當您在調試器中啟動程序時,調試堆會自動啟用,這與使用調試器附加到已在運行的程序相反。

Mario Hewardt和Daniel Pravat所著的Advanced Windows Debugging一書中有一些有關Windows堆的不錯的信息,事實證明,有關堆的章節在網站上作為示例章節而出現

當你做

pImage=m_pStretchedDefaultThumbImage;

m_pStretchedDefaultThumbImage是否可能未初始化?

如果在您粘貼的第三行上pImage == NULL會發生什么? 在這種情況下, rcShowImagercShowImage分配值。

暫無
暫無

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

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