繁体   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