---------------------------------
Debug Assertion Failed!Program : E:\debug\demo.exe
File: afxwin2.inl
Line: 126For information on how your reogram can cause an assertion
failure,see the Vc++ documentation on asserts
---------------------------------
这个错误是怎么造成的?
怎么改?
Debug Assertion Failed!Program : E:\debug\demo.exe
File: afxwin2.inl
Line: 126For information on how your reogram can cause an assertion
failure,see the Vc++ documentation on asserts
---------------------------------
这个错误是怎么造成的?
怎么改?
{
// TODO: Add your control notification handler code here
CFile File=0;
CFileDialog dlg(TRUE,0,0,OFN_HIDEREADONLY,"位图文件|*.bmp|所有文件|*.*||",this);
if (dlg.DoModal()==IDOK)
{
FileName=dlg.GetPathName();
if (!File.Open(FileName,CFile::modeRead)) return;
// TODO: add loading code here
if (lpBitmap) delete lpBitmap;
nLen=File.GetLength();
lpBitmap=new BYTE[nLen];
File.Read(lpBitmap,nLen);
LoadBitmap();
if (lpBitmap) source.SetImage(nWidth,nHeight,lpBits);
}
}void CDemoDlg::LoadBitmap()
{
BITMAPINFOHEADER *pInfo;
pInfo=(BITMAPINFOHEADER *)(lpBitmap+sizeof(BITMAPFILEHEADER));
nWidth=pInfo->biWidth;
nByteWidth=nWidth*3;
if (nByteWidth%4) nByteWidth+=4-(nByteWidth%4);
nHeight=pInfo->biHeight;
if (pInfo->biBitCount!=24)
{
if (pInfo->biBitCount!=8)
{
AfxMessageBox("无效位图");
delete lpBitmap;
lpBitmap=0;
return;
}
unsigned int PaletteSize=1<<pInfo->biBitCount;
if (pInfo->biClrUsed!=0 && pInfo->biClrUsed<PaletteSize) PaletteSize=pInfo->biClrUsed;
lpBits=lpBitmap+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
RGBQUAD *pPalette=(RGBQUAD *)lpBits;
lpBits+=sizeof(RGBQUAD)*PaletteSize;
nLen=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+nByteWidth*nHeight;
BYTE *lpTemp=lpBitmap;
lpBitmap=new BYTE[nLen];
BITMAPFILEHEADER bmh;
BITMAPINFOHEADER bmi;
bmh.bfType='B'+'M'*256;
bmh.bfSize=nLen;
bmh.bfReserved1=0;
bmh.bfReserved2=0;
bmh.bfOffBits=54;
bmi.biSize=sizeof(BITMAPINFOHEADER);
bmi.biWidth=nWidth;
bmi.biHeight=nHeight;
bmi.biPlanes=1;
bmi.biBitCount=24;
bmi.biCompression=BI_RGB;
bmi.biSizeImage=0;
bmi.biXPelsPerMeter=0;
bmi.biYPelsPerMeter=0;
bmi.biClrUsed=0;
bmi.biClrImportant=0;
int nBWidth=pInfo->biWidth;
if (nBWidth%4) nBWidth+=4-(nBWidth%4);
memset(lpBitmap,0,nLen);
memcpy(lpBitmap,&bmh,sizeof(BITMAPFILEHEADER));
memcpy(lpBitmap+sizeof(BITMAPFILEHEADER),&bmi,sizeof(BITMAPINFOHEADER));
BYTE *lpBits2=lpBitmap+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
int x,y,p1,p2,Palette;
for(y=0;y<nHeight;y++)
{
for(x=0;x<nWidth;x++)
{
p1=y*nBWidth+x;
p2=y*nByteWidth+x*3;
if (lpBits[p1]<PaletteSize) Palette=lpBits[p1];
else Palette=0;
lpBits2[p2]=pPalette[Palette].rgbBlue;
lpBits2[p2+1]=pPalette[Palette].rgbGreen;
lpBits2[p2+2]=pPalette[Palette].rgbRed;
}
}
delete lpTemp;
}
lpBits=lpBitmap+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
if (lpBackup) delete lpBackup;
lpBackup=new BYTE[nLen];
memcpy(lpBackup,lpBitmap,nLen);
}void CDemoDlg::OnClick(WPARAM pos,LPARAM dump)
{ int ID=buttonid[pos];
switch(ID)
{
case INPUT_FILE:
OpenFile();
break;
}
}
在Debug Assertion Failed!那个对话框中,选择“重试”按钮进入调试
点击菜单view->debug windows->call stack,在stack窗口中点击双击各个函数,找到你出错的代码。
Invalidate();
CImageWnd::SetImage(int 158, int 64, const void * 0x01546efa) line 211
CDemoDlg::OpenFile() line 506
CDemoDlg::OnClick(unsigned int 0, long 0) line 527
CWnd::OnWndMsg(unsigned int 11024, unsigned int 0, long 0, long * 0x009ff0ac) line 1815 + 17 bytes
CWnd::WindowProc(unsigned int 11024, unsigned int 0, long 0) line 1585 + 30 bytes
AfxCallWndProc(CWnd * 0x009ff3a4 {CDemoDlg hWnd=???}, HWND__ * 0x00000e70, unsigned int 11024, unsigned int 0, long 0) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x00000e70, unsigned int 11024, unsigned int 0, long 0) line 368
KERNEL32! bff7363b()
KERNEL32! bff94737()
009f81c2()他说是这几个出错了,帮我看看这个是什么意思吧
不是很明白
是啊
你能看看是哪里错了吗?
CImageWnd::SetImage(int 158, int 64, const void * 0x01546efa) line 211应该是source.SetImage中调用了Invalidate函数。调用的时候可能你的窗口还没有创建。
source是个什么东西?你调用CDemoDlg::OnClick的时候这个窗口创建了吗?