   Problem with my surface maybe? help! [solved]
  Im kinda lost here so any help would be appreciated I have never run into a problem like this before, I tried checking to see if there was any HDC's I was not releasing but no luck :/Well I'm a bad person because really I have no information on what is causing this.. but maybe someone knows, what seems like randomly my windows application (which seems to run fine) will just go blank I have even started it and not pressed anything (other than loading my map), and let it sit, and I come back a few minutes later and its the same black screen.The resources for the program as far as memory footprint don't changeThe program is not crashed its still using the same resources, it just seems like windows is no longer processing messages properly, or trying to draw my windows controls, side note, some times it will display my directx buffer im blting to it, other times it wont..I have ran through my windows message pump, where I do my flip from my "back buffer" and I cannot seem to find why its doing this... I would think if it was a direct-x problem the windows controls would still draw properly... and since its not actually crashing it doesn't bomb out when debugging...My message pumpMSG msg;//message pumpfor(;;){//look for a messageif(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){//check that we arent quittingif(msg.message==WM_QUIT) break;//translate messageTranslateMessage(&msg);//dispatch messageDispatchMessage(&msg);}else{Program_Running();}}Program_Shutdown();//Windows Message PumpLRESULT CALLBACK TheWindowProc(HWND hWndMain,UINT uMsg,WPARAM wParam,LPARAM lParam){int wmId, wmEvent;//which message did we get?switch(uMsg){case WM_MOVE:{EditorData.windowsinfo.MainWindowX = LOWORD(lParam);EditorData.windowsinfo.MainWindowY = HIWORD(lParam);//set primeblit point to client 0,0EditorData.windowsinfo.ptPrimeBlt.x=0;EditorData.windowsinfo.ptPrimeBlt.y=0;//convert to screen coordinatesClientToScreen(EditorData.windowsinfo.hWndMain,&EditorData.windowsinfo.ptPrimeBlt);//return(0);}break;case WM_MOUSEMOVE:{//point to contain mouse coordsPOINT ptMouse;ptMouse.x=(int)LOWORD(lParam);ptMouse.y=(int)HIWORD(lParam);EditorData.mouse.EditorMouse.x=ptMouse.x;EditorData.mouse.EditorMouse.y=ptMouse.y;//Map x = mapx / tilesizeX + tileOffset//return(0);}break;case WM_RBUTTONDOWN:{POINT ptMouse;ptMouse.x=(int)LOWORD(lParam);ptMouse.y=(int)HIWORD(lParam);//Map x = mapx / tilesizeX + tileOffsetRightMouseClick(ptMouse);//return(0);}break;case WM_LBUTTONDOWN:{POINT ptMouse;ptMouse.x=(int)LOWORD(lParam);ptMouse.y=(int)HIWORD(lParam);//Map x = mapx / tilesizeX + tileOffsetLeftMouseClick(ptMouse);//return(0);}break;case WM_KEYDOWN:{if(wParam==VK_RIGHT) //RIGHT{if (EditorData.editorinfo.OffsetX >= 0 && EditorData.editorinfo.OffsetX < TILEMAP_MAX_X -10){EditorData.editorinfo.OffsetX++;}}else if(wParam==VK_LEFT) //LEFT{if (EditorData.editorinfo.OffsetX > 0){EditorData.editorinfo.OffsetX--;}}else if(wParam==VK_UP) //UP{if (EditorData.editorinfo.OffsetY > 0){EditorData.editorinfo.OffsetY--;}}else if(wParam==VK_DOWN) //DOWN{if (EditorData.editorinfo.OffsetY >= 0 && EditorData.editorinfo.OffsetY < TILEMAP_MAX_Y -10){EditorData.editorinfo.OffsetY++;}}else if(wParam==VK_NEXT) //PAGE DOWN{if (EditorData.editorinfo.StartTile < EditorData.editorinfo.tsTileMap.GetTileCount()){EditorData.editorinfo.StartTile+=5;}}else if(wParam==VK_PRIOR) //PAGE DOWN{if (EditorData.editorinfo.StartTile >= 5){EditorData.editorinfo.StartTile-=5;}}//return(0);}break;case WM_COMMAND:{wmId    = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections:WMCommandHandler(wmId,wmEvent);}break;case WM_DESTROY://the window is being destroyed{//tell the application we are quittingPostQuitMessage(0);//handled message, so return 0//return(0);}break;case WM_PAINT://the window needs repainting{//a variable needed for painting informationPAINTSTRUCT ps;//start paintingHDC hdc=BeginPaint(hWndMain,&ps);//end paintingEndPaint(hWndMain,&ps);//handled message, so return 0//return(0);}break;}//pass along any other message to default message handlerreturn(DefWindowProc(hWndMain,uMsg,wParam,lParam));}Here is how im flipping my offscreen surface (my back buffer) to my primary surfacevoid DDFlip(){//copy from "back buffer" onto primary//declare rectanglesRECT rcSrc;RECT rcDst;//set up source rectangleSetRect(&rcSrc,0,0,EditorData.windowsinfo.WindowSizeX,EditorData.windowsinfo.WindowSizeY);//copy source rect to destination rectCopyRect(&rcDst,&rcSrc);//offset by the screen coordinate of the window's client areaOffsetRect(&rcDst,EditorData.windowsinfo.ptPrimeBlt.x,EditorData.windowsinfo.ptPrimeBlt.y);//performa the blitlpddsMain->Blt(&rcDst,lpddsBack,&rcSrc,DDBLT_WAIT,NULL);return;}[Edited by - yewbie on May 10, 2009 5:35:41 PM]
  Additional note, it seems to corrupt the start bar and any windows I have up until I minimize them or right click on my screen and refreshAlso - every frame I checkif (lpddsMain->IsLost())and if it is I calllpdd->RestoreAllSurfaces(); maybe this is the culprit?   ;  There's one thing I see straight away; that PeekMessage() look is wrong. It should be:MSG msg;bool bQuit = false;//message pumpdo{   //look for a message   while(PeekMessage(&msg,NULL,0,0,PM_REMOVE))   { //check that we arent quitting if(msg.message==WM_QUIT)    bQuit = true; //translate message TranslateMessage(&msg); //dispatch message DispatchMessage(&msg);   }   if(!bQuit) Program_Running();} while(!bQuit);Program_Shutdown();The point being that you need to process all window messages before running one program update. Otherwise, if Program_Running() causes a message to be sent to the window, your message queue will fill up and the app will get slower and slower and have unexpected behaviour.As for the DirectDraw related problems, it's been a long time since I used it, but do you have a clipper set on your window? I believe that without one, DirectDraw can draw over the window all over the place.Also, if you're not already aware, DirectDraw is out of date. You should really be using D3D, and on Vista and above, DirectDraw is emulated through D3D anyway.   ;  Thanks for the comment Evil Steve, I'm going to try that out and see if it solves the problem (I think it very well might), I didn't realize I was only processing 1 message a loop!And I'm just doing 2d, do you think its worth all the hassle of converting all my graphical stuff over to d3d?, would I see a performance increase? (I don't really need it it runs great even on old machines)Not to mention I have messed around with some stuff with DX9 and it seems alot more complex, but all things progress I guess I will start looking into it =pEDIT:It still did it sadly with the new message pump... Next im going to try running it in release mode and see if something weird with debug mode is causing it.   ;Quote:As for the DirectDraw related problems, it's been a long time since I used it, but do you have a clipper set on your window? I believe that without one, DirectDraw can draw over the window all over the place.Also, if you're not already aware, DirectDraw is out of date. You should really be using D3D, and on Vista and above, DirectDraw is emulated through D3D anyway.I have a clipper and it works fine until that mysterious point it decides to stop working...Its really strange its almost as if the windows portion of the code stops working, or is running at like 1 frame every few seconds, so it goes from like 30 fps to almost no frames instantly and windows can't keep up with messages.. this is really frustrating, does anyone know how I can monitor the program and see what it is doing at a specific point?  like some kind of process watcher?I tried using dependency walker but it didn't give me any information I could use.Do you think maybe I am running into some weird using dx7 on a vista machine problem maybe?   ;  Maybe this is another clue, when the program is locked and everything is black if I try to take a screenshot using windows built in shift-control-printscreen, it doesn't actually work so this would confirm to me that the message pump is not working properly or something like that.   ;  Well Windows taking a screenshot of your display has nothing to do with your program's message loop :). I'm sorry but I can't actually help out with your problem.   ;  Well I was able to find out what was causing this...I was creating various pens to do simple drawing hPen1 = CreatePen(PS_SOLID, 5, RGB(155, 55, 55));like so... but I did not know that even though that function was going out of scope the pen never got deleted... deleting the pens before returning on that function seemed to solve the problem.I wonder why it was crashing the whole windows interface through creating a ton of pens.DeleteObject(hPen1); FTW   