【问题标题】:.Access violation reading location.访问冲突读取位置
【发布时间】:2008-11-06 03:08:22
【问题描述】:

我遇到了一个非常奇怪的问题。

代码如下:

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

【问题讨论】:

    标签: c++ boost smart-pointers access-violation


    【解决方案1】:

    0xfeeefeee 是 Windows 堆的调试版本(不是 C 运行时堆)用于未初始化内存的填充模式。 0xfeeefef20xfeeefeee+4。听起来您正在取消引用位于(或复制自)从堆分配的内存块中的未初始化指针。

    当您在调试器中启动程序时,调试堆会自动启用,而不是使用调试器附加到已经运行的程序。

    Mario Hewardt 和 Daniel Pravat 所著的Advanced Windows Debugging一书提供了一些关于 Windows 堆的不错信息,而关于堆的章节是up on the web site as a sample chapter

    【讨论】:

      【解决方案2】:

      当你这样做时

      pImage=m_pStretchedDefaultThumbImage;
      

      是否有可能是 m_pStretchedDefaultThumbImage 未初始化?

      【讨论】:

        【解决方案3】:

        如果pImage == NULL 在您粘贴的第三行会发生什么?在这种情况下,rcShowImage 不会被赋值。

        【讨论】:

        • 看起来 rcShowImage 在堆栈上(成员用“.”访问),所以访问它应该没有问题。
        • 是的,但我们不知道它是什么类型以及构造函数是否做了任何明智的事情。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-12-31
        • 2016-05-28
        • 2017-01-09
        • 2014-11-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多