访问冲突读取位置

访问冲突读取位置

本文介绍了访问冲突读取位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've met a really strange problem.

代码如下:

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

I have checked the pImage, I am sure when graphics.DrawImage is called, it is not NULL.


  • 为什么会出现这样的问题?

  • 什么是 0xfeeefef2 ? b $ b

推荐答案

0xfeeefeee 的Windows堆(而不是C运行时堆)用于未初始化的内存。 0xfeeefef2 0xfeeefeee + 4 。它听起来像是你解除引用一个未初始化的指针位于(或复制自)从堆分配的内存块。

0xfeeefeee is a fill pattern that the debug version of the Windows heap (not the C runtime heap) uses for uninitialized memory. 0xfeeefef2 is 0xfeeefeee+4. It sounds like you're dereferencing an uninitialized pointer located in (or copied from) a block of memory allocated from the heap.

调试堆在启动时自动启用

The debug heap automatically gets enabled when you start your program in the debugger, as opposed to attaching to an already-running program with the debugger.

由Mario Hewardt和Daniel Pravat提供了关于Windows堆的一些不错的信息,结果是堆的一章是。

这篇关于访问冲突读取位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 14:28