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?
4

3 に答える 3

11

0xfeeefeeeWindows ヒープ (C ランタイム ヒープではない) のデバッグ バージョンが初期化されていないメモリに使用する塗りつぶしパターンです。0xfeeefef2です0xfeeefeee+4。ヒープから割り当てられたメモリのブロックにある (またはそこからコピーされた) 初期化されていないポインタを逆参照しているようです。

デバッガーで既に実行中のプログラムにアタッチするのではなく、デバッガーでプログラムを開始すると、デバッグ ヒープが自動的に有効になります。

Mario Hewardt と Daniel Pravat による本Advanced Windows Debuggingには、Windows ヒープに関する適切な情報が記載されており、ヒープに関する章がサンプルの章として Web サイトに掲載されていることがわかります。

于 2008-11-06T03:47:14.087 に答える
2

あなたがするとき

pImage=m_pStretchedDefaultThumbImage;

m_pStretchedDefaultThumbImage が初期化されていない可能性はありますか?

于 2008-11-06T03:32:58.483 に答える
0

pImage == NULL3 行目に貼り付けたらどうなりますか? その場合、 にrcShowImageは値が割り当てられません。

于 2008-11-06T03:28:55.230 に答える