2008-11-06 89 views
0

我遇到了一個非常奇怪的問題。。訪問衝突的閱讀地點

的代碼如下:

::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

回答

0

如果您粘貼第三行的pImage == NULL會發生什麼?在這種情況下,rcShowImage未分配一個值。

+0

它看起來像rcShowImage在堆棧(用「。」)訪問的成員,因此訪問它應該不成問題。 – 2008-11-06 03:31:57

2

當你

pImage=m_pStretchedDefaultThumbImage; 

有沒有一種可能性,即m_pStretchedDefaultThumbImage未初始化?

10

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

當您在調試器中啓動程序時,調試堆會自動啓用,而不是使用調試器附加到已經運行的程序。

Advanced Windows Debugging由馬里奧·赫沃特和丹尼爾Pravat具有有關Windows堆一些體面的信息,並且事實證明,上堆的一章是up on the web site as a sample chapter