   GDI Rectangles disappear after a minute or so
  Okay I am making a simple networked based pong imitation using GDI(should have just used DX). Here is the problem I am having if the game runs for a minute or two the paddles(rectangles)disappear. However if I change the background from white to black and make the rectangles white then they stay.  Also when I render the rectangles and try to fill them with a color all I get is black lines in side my rectangles. Here is the code of how I am rendering a rectangle. I took out the object abstraction for simplicity’s sake. Any suggestions welcomed.This is how I am calling GameLoop.while (1) {if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){if(msg.message == WM_QUIT)break;TranslateMessage(&msg);DispatchMessage(&msg);}//close if for PeekMessageelse{if(!g_gamePaused && LockFrameRate(60)){GameLoop();}}}This is the gameloop functionbool GameLoop(){if( GetAsyncKeyState( VK_ESCAPE ) ){GameShutdown();PostQuitMessage(0);}string title = "Pong with GDI and TCP sockets!";stringstream score; HDC hdc = GetDC(g_hwnd);HDC hdcBackBuffer = CreateCompatibleDC(hdc);HBITMAP hbitmap = CreateCompatibleBitmap(hdcBackBuffer,800,600);RECT rect;GetClientRect(g_hwnd,&rect);SelectObject(hdcBackBuffer,(HANDLE)hbitmap);FillRect(hdcBackBuffer,&rect,CreateSolidBrush(RGB(255, 255,255)));rect.left=100;rect.bottom = 100;rect.right = 120;rect.top = 120;Rectangle(hdcBackBuffer,100,100,120,120);FillRect(hdcBackBuffer,&rect,CreateSolidBrush(RGB(255, 0,0)));BitBlt(hdc,0,0,800,600,hdcBackBuffer,0,0,SRCCOPY);DeleteObject(hdcBackBuffer);DeleteObject(hbitmap);ReleaseDC(g_hwnd,hdc);return true
  I'm not sure about the problem, but theres a couple of general problems I can see there. Firstly, this line:SelectObject(hdcBackBuffer,(HANDLE)hbitmap);You need to store the old HBITMAP and restore it before you delete the DC or bitmap. I'm not sure what the GDI will be doing, but if its reference counted somehow then not restoting the old backbuffer will mean that either the DC or HBIMAP isn't destroyed properly. If you leak resources continually (especially since you're creating the DC and bitmap every game loop) then the GDI will eventually run out of resources and things will start going weird.Secondly, you really shouldn't be creating a DC and bitmap every game loop. You should create them (and call SelectObject()) before the loop, and free them after. You may have already done that and just shown the code like that for clarity of course.One way to check if you have a resource leak (under Win2k/XP/NT) is to open the task manager, goto the View menu -> Select Columns, and check the "GDI Objects" box. Then run your app, and keep an eye on the task manager. If your apps GDI Object count continually increases, you have a resource leak somewhere.   ;  The only thing that I see wrong with it right off the bat is that you're not supposed to call a DeleteObject on drawing objects that are currently selected (the hbitmap).  Store the original and reselect before calling that.  Also, DeleteDC should be used for a created device context, not DeleteObject, which is more likely to be the problem as you might be running out of context handles.If that doesn't work, try adding a trace on your rectangle positions to make sure it's not just a position calculation error.  edit: I agree with Steve, btw.  Creating and destroying the same DC's and bitmaps repeatedly every draw loop is a serious waste of processor cycles.-fel   ;  Thanks for the help Evil Steve and felisandria. I figured out my problem it was a resource leak at this line of code.FillRect(hdcBackBuffer,&rect,CreateSolidBrush(RGB(255, 255,255)));Quote:edit: I agree with Steve, btw. Creating and destroying the same DC's and bitmaps repeatedly every draw loop is a serious waste of processor cycles.I agree as well...;)Thanks again for the help guys.