.访问违规读取位置 [英] .Access violation reading location
问题描述
我遇到了一个非常奇怪的问题.
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
?
推荐答案
0xfeeefeee
是 Windows 堆(不是 C 运行时堆)的调试版本用于未初始化内存的填充模式.0xfeeefee2
是 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 合着的Advanced Windows Debugging这本书有一些不错的有关 Windows 堆的信息,结果证明关于堆的章节是 在网站上作为示例章节.
The book Advanced Windows Debugging by Mario Hewardt and Daniel Pravat has some decent information about the Windows heap, and it turns out that the chapter on heaps is up on the web site as a sample chapter.
这篇关于.访问违规读取位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!