2008-11-06 90 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