Jump to content
  • Advertisement

Archived

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

Obsidian Kindragon

Problem when locking newly created surface in Windowed mode

This topic is 5842 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

Hello. I''ve just started a small windowed program and I used to be able to Lock the Primary or the Secondary surface, but over the last few days the exact same codes will return a DDERR_SURFACEBUSY error whenever I try locking any surface. Here''s a snippet of my code: int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { MSG msg; //SETUP DIRECTDRAW INTERFACE if(DirectDrawCreate(NULL, &lpdd, NULL)!=DD_OK) { return(0); } lpdd->SetCooperativeLevel(hWnd, DDSCL_NORMAL); //SETUP PRIMARY SURFACE memset(&ddsd,0,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; if(lpdd->CreateSurface(&ddsd,&lpddsPrimary,NULL)!=DD_OK) { return(0); } //CREATE SECONDARY SURFACE memset(&ddsd,0,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; ddsd.dwWidth = 600; ddsd.dwHeight = 400; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; if(lpdd->CreateSurface(&ddsd,&lpddsSecondary,NULL)!=DD_OK) { return(0); } //ATTEMPT TO LOCK SECONDARY SURFACE //THIS RETURNS A DDERR_SURFACEBUSY ERROR lpddsSecondary->LOCK(NULL, &ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,NULL); //CREATE MAIN WINDOW WNDCLASS wMain; wMain.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; wMain.lpfnWndProc = MainWindowProc; wMain.cbClsExtra = 0; wMain.cbWndExtra = 0; wMain.hInstance = hInstance; wMain.hIcon = LoadIcon(NULL,IDI_APPLICATION); wMain.hCursor = LoadCursor(NULL,IDC_ARROW); wMain.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wMain.lpszMenuName = NULL; wMain.lpszClassName = "TileSet"; if(!RegisterClass(&wMain)) { return(0); } if(!(hWnd = CreateWindow("TileSet", "Tile Program", WS_POPUP, 0, 0, 600, 400, NULL, NULL, hInstance, NULL))) { return(0); } while(1) { if(GetAsyncKeyState(VK_ESCAPE) & 0x8000 ? 1 : 0) { PostQuitMessage(0); } if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if(msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } } if(lpddsSecondary != NULL) { lpddsSecondary->Release(); } if(lpddsPrimary != NULL) { lpddsPrimary->Release(); } if(lpdd != NULL) { lpdd->Release(); } return(msg.wParam); }

Share this post


Link to post
Share on other sites
Advertisement
Nevermind. I found out the problem. It was due to trying to debug the program with a breakpoint between a lpddsSurface->Lock() and lpddsSurface->Unlock() without having the DDLOCK_NOSYSLOCK flag initiated. The debugger would crash the first time after compiling and then give the DDERR_SURFACEBUSY error whenever I tried to lock the surface, but I fixed it by adding the DDLOCK_NOSYSLOCK flag when locking.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!