Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Jaxks

What's with locking surface

This topic is 6933 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In following is no compiling errors but when I run it program stucks to GetDC funktion in funktion Updateframe. I use VC++ 6 Introductory edition and dx7a sdk. The error what windows says is "Acces violatition in .....". Please help I´ve think this long. // FLIPTEST.cpp : Defines the entry point for the application. // //Precompiled stuff #include "stdafx.h" //Globals LPDIRECTDRAW7 lpdd7 =NULL; LPDIRECTDRAWSURFACE7 psurface =NULL; LPDIRECTDRAWSURFACE7 bsurface =NULL; DDSURFACEDESC2 ddSd; DDSCAPS2 ddsCaps; //Functions void UpdateFrame() { HDC hdc; BOOL flag=1; char *jono1="Front Buffer"; char *jono2="Back Buffer"; if(bsurface->GetDC(&hdc)) { SetBkColor(hdc,RGB(0,0,255)); SetTextColor(hdc,RGB(34,56,122)); if(flag) { TextOut(hdc,200,300,jono1,strlen(jono1)); flag=0; } else { TextOut(hdc,56,78,jono2,strlen(jono2)); flag=1; } } bsurface->ReleaseDC(hdc); } BOOL ErrorProc(HWND hwnd,HRESULT hret); BOOL CleanAll(); //Handles all errors messages from directdraw BOOL ErrorProc(HWND hwnd,HRESULT hret) { switch(hret) { case DD_OK: { return 0; }break; case DDERR_ALREADYINITIALIZED: { CleanAll(); MessageBox(hwnd,"DirectX objekti on jo olemassa","DirectX Virhe",MB_OK); return(SendMessage(hwnd,WM_QUIT,0,0)); }break; default: { CleanAll(); MessageBox(hwnd,"Other Error","DirectX Error",MB_OK); return(SendMessage(hwnd,WM_QUIT,0,0)); }break; } return(1); } LRESULT CALLBACK WindowProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam) { HDC hdc; PAINTSTRUCT ps; HRESULT DxResult=NULL; switch(msg) { case WM_PAINT: { hdc=BeginPaint(hwnd,&ps); EndPaint(hwnd,&ps); return 0; }break; case WM_QUIT: { CleanAll(); PostQuitMessage(0); return(0); }break; case WM_SETCURSOR: { SetCursor(NULL); return TRUE; }break; case WM_KEYDOWN: // Handle any non-accelerated key commands switch (wparam) { case VK_ESCAPE: case VK_F12: PostMessage(hwnd, WM_QUIT, 0, 0); return 0; }break; default:break; } return (DefWindowProc( hwnd, msg,wparam,lparam)); } BOOL CleanAll() { if(lpdd7) { if(psurface) { psurface->Release(); psurface=NULL; } if(bsurface) { bsurface->Release(); bsurface=NULL; } lpdd7->Release(); lpdd7=NULL; } return(1); } static HWND Initialize(HINSTANCE hinst,HWND hwnd) { WNDCLASS wc; wc.cbClsExtra=NULL; wc.cbWndExtra=NULL; wc.hbrBackground=static_cast(GetStockObject(BLACK_BRUSH)); wc.hCursor=LoadCursor(hinst,IDC_ARROW); wc.hIcon=LoadIcon(hinst,MAKEINTRESOURCE(IDI_ICON1)); wc.hInstance=hinst; wc.lpszClassName="Game console"; wc.style=CS_HREDRAW/CS_VREDRAW; wc.lpfnWndProc= WindowProc; wc.lpszMenuName=NULL; if(!RegisterClass(&wc)) { CleanAll(); return(0); } if(hwnd!=CreateWindowEx(NULL,"Game console","Ddraw Program",WS_POPUPWINDOW/WS_VISIBLE,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),NULL,NULL,hinst,NULL)) { CleanAll(); return(0); } HRESULT DxResult; DxResult=DirectDrawCreateEx(NULL,(VOID **)&lpdd7,IID_IDirectDraw7,NULL); if(DxResult!=DD_OK) { ErrorProc(hwnd,DxResult); return(0); } DxResult=lpdd7->SetCooperativeLevel(hwnd,DDSCL_EXCLUSIVE/DDSCL_FULLSCREEN); if(DxResult!=DD_OK) { ErrorProc(hwnd,DxResult); return(0); } DxResult=lpdd7->SetDisplayMode(800,600,8,0,NULL); if(DxResult!=DD_OK) { ErrorProc(hwnd,DxResult); return(0); } ZeroMemory(&psurface,sizeof(psurface)); ddSd.dwSize=sizeof(psurface); ddSd.dwFlags = DDSD_CAPS/DDSD_BACKBUFFERCOUNT; ddSd.ddsCaps.dwCaps=DDSCAPS_PRIMARYSURFACE/DDSCAPS_COMPLEX/DDSCAPS_FLIP; ddSd.dwBackBufferCount = 1; DxResult=lpdd7->CreateSurface(&ddSd,&psurface,NULL); if(DxResult!=DD_OK) { ErrorProc(hwnd,DxResult); return 0; } ddsCaps.dwCaps=DDSCAPS_BACKBUFFER; psurface->GetAttachedSurface(&ddsCaps,&bsurface); return hwnd; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hwnd=0; hwnd=Initialize(hInstance,hwnd); MSG msg; UpdateFrame(); while(1) { if (PeekMessage(&msg,hwnd,0,0,PM_REMOVE)) { // test if this is a quit if (msg.message == WM_QUIT) break; // translate any accelerator keys TranslateMessage(&msg); // send the message to the window proc DispatchMessage(&msg); } // end if UpdateFrame(); } return msg.wParam; }

Share this post


Link to post
Share on other sites
Advertisement
You need to check the return values of all those DirectX calls. bsurface is probably NULL due to not being set up properly.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!