Access violation???
bool UpdateFrame(){
SetRect(&src,0,0,32,32);
if(FAILED(lpBackBuffer->Blt(NULL,NULL,NULL,DDBLT_WAIT|DDBLT_COLORFILL,&ddbltfx)))
return FALSE;
if(FAILED(lpBackBuffer->Blt(&dest,lpSecondary,&src,DDBLT_WAIT,NULL)))
return FALSE;
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd){
MSG msg;
HWND hwnd;
WNDCLASS wc;
wc.nostyle= CS_HREDRAW|CS_VREDRAW;
wc.hInstance=hInstance;
wc.lpfnWndProc=WindowProc;
wc.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wc.hCursor=LoadCursor(hInstance,IDC_ARROW);
wc.hIcon=LoadIcon(hInstance,IDI_APPLICATION);
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.lpszClassName="Window";
wc.lpszMenuName=NULL;
RegisterClass(&wc);
hwnd=CreateWindowEx(WS_EX_TOPMOST,"Window","Test",WS_POPUP,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd);
ShowCursor(FALSE);
if(FAILED(DirectDraw(hwnd)))
return FALSE;
if(FAILED(LoadImage(lpSecondary,"tiles.bmp")))
return FALSE;
if(FAILED(LoadImage(lpHero,"sprite.bmp")))
return FALSE;
ddbltfx.dwSize=sizeof(DDBLTFX);
ddbltfx.dwFillColor=0;
SetRect(&dest,0,0,32,32);
while(TRUE){
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else{
UpdateFrame();
lpPrimary->Flip(NULL,DDFLIP_WAIT);
while(GetTickCount()-30<70);
}
};
return msg.wParam;
};
When the window terminates I recieve an error saying access violation at the point in function UpdateFrame() where it first blits to the backbuffer. Any idea what Im doing wrong?
Thanks in advance,
Zorb
Where are you creating lpBackBuffer? It looks like the pointer is not valid.
I will not make a list of links... I will not make a list of links... I will not make a list of links...
Invader''s Realm
I will not make a list of links... I will not make a list of links... I will not make a list of links...
Invader''s Realm
DDSURFACEDESC ddsd;ddsd.dwSize=sizeof(DDSURFACEDESC);ddsd.dwFlags=DDSD_CAPS|DDSD_BACKBUFFERCOUNT;ddsd.ddsCaps.dwCaps=DDSCAPS_COMPLEX|DDSCAPS_FLIP|DDSCAPS_PRIMARYSURFACE;ddsd.dwBackBufferCount=1;if(FAILED(lpDD->CreateSurface(&ddsd,&lpPrimary,NULL)))return FALSE;ddsd.ddsCaps.dwCaps=DDSCAPS_BACKBUFFER;if(FAILED(lpPrimary->GetAttachedSurface(&ddsd.ddsCaps,&lpBackBuffer)))return FALSE;
It looks like you never break out of your while loop. So you may be releasing lpBackBuffer and then your loop continues, UpdateFrame() is called and you try and blt, and it fails as lpBackBuffer no longer exists.
You could try putting the following code in your while(TRUE) loop:
if(msg.message == WM_QUIT){
break;
}
just after the DispatchMessage(&msg) line.
Hope this helps.
You could try putting the following code in your while(TRUE) loop:
if(msg.message == WM_QUIT){
break;
}
just after the DispatchMessage(&msg) line.
Hope this helps.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement