Results 1 to 2 of 2

Thread: BitBlt Leak and error

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2009
    Posts
    2

    BitBlt Leak and error

    Hello. I am having trouble with this little test program I made. It involves some rectangles, checks collisions and other stuff. Everything works fine, except that after a while, All the rectangles on screen go blank, leaving only their lines. I dont know what causes this, but I guess it may be a leak because when I see the program in Task Manager the memory that is dedicated to it continuously grows, until the glitch happens, then it stays the same.

    Done in C, using windows.h and Dev-C++

    Here is my Paint routine, I assume the trouble is here, but in case I included the whole code as an attachment.

    Code:
    case WM_PAINT:
                 {
                 hdc = BeginPaint(hwnd,&ps);                        
                  
                 GetClientRect(hwnd,&cr);             
                 
                 hdcBuffer = CreateCompatibleDC(hdc);
                 hbmBuffer = CreateCompatibleBitmap(hdc,cr.right,cr.bottom);
                 hbmOldBuffer = /*(HBITMAP)*/SelectObject(hdcBuffer,hbmBuffer);
                 
                 
                 FillRect(hdcBuffer,&cr,CreateSolidBrush(RGB(255,255,100)));
                 brs = CreateSolidBrush(RGB(255,0,0));
    
                 SelectObject(hdcBuffer,CreateSolidBrush(RGB(100,100,100)));
                 Rectangle(hdcBuffer,re2.left,re2.top,re2.right,re2.bottom);
                 
                 SelectObject(hdcBuffer,CreateSolidBrush(RGB(0,0,200)));
                 Rectangle(hdcBuffer,arrast.left,arrast.top,arrast.right,arrast.bottom);
                 
                 SelectObject(hdcBuffer,CreateSolidBrush(RGB(0,0,0)));
                 Rectangle(hdcBuffer,drop.left,drop.top,drop.right,drop.bottom);
                 
                 if(disparo == 1){
                 SelectObject(hdcBuffer,CreateSolidBrush(RGB(100,50,0)));
                 Rectangle(hdcBuffer,bala.left,bala.top,bala.right,bala.bottom);
                 }
                 
                 SelectObject(hdcBuffer,brs);
                 Rectangle(hdcBuffer,re.left,re.top,re.right,re.bottom);
                 
                 if(flag8==1){
                 SelectObject(hdcBuffer,CreateSolidBrush(RGB(200,0,200)));
                 Rectangle(hdcBuffer,check2.left,check2.top,check2.right,check2.bottom);
                              
                              }
                 
                 SetBkMode(hdcBuffer,TRANSPARENT);
                 TextOut(hdcBuffer,400,20,"Uvaz Colision Test",18);
                 if(flag1==1)
                 TextOut(hdcBuffer,400,40,"Colision Detectada",18);
                 if(flag2==1)
                 TextOut(hdcBuffer,400,60,"Colision Detectada",18);
                 if(flag3==1)
                 TextOut(hdcBuffer,400,80,"Colision Detectada",18);
                 if(flag4==1)
                 TextOut(hdcBuffer,400,100,"Colision Detectada",18);
                 
                 if(flag6==1){
                 TextOut(hdcBuffer,400,120,"Maus Detectado",14);
                 char cad[15];
                 //cad = malloc(sizeof(char)*15);
                 sprintf(cad,"X: %d Y: %d ",maus.x,maus.y);
                 TextOut(hdcBuffer,450,140,cad,strlen(cad));
                 }
                 
                 if(flag7==1)
                 TextOut(hdcBuffer,400,160,"Bloque Tocado",13);             
                 
                 
                 BitBlt(hdc,0,0,cr.right,cr.bottom,hdcBuffer,0,0,SRCCOPY);
                 
                 SelectObject(hdcBuffer,hbmOldBuffer);
                 
                 DeleteDC(hdcBuffer);
                 DeleteObject(hbmBuffer);
                                     
                 EndPaint(hwnd,&ps);
                 } 
                 break;
    And the variables:
    Code:
            HDC hdc,hdcBuffer;
            PAINTSTRUCT ps;   
            static RECT re,re2,check,check2,bala,cr,arrast,drop,screen;
            static int xx;
            static int yy;
            static int contador,scon;
            static int disparo;
            static int xdis,ydis,dx,dy;
            static int flag1=0,flag2=0,flag3=0,flag4=0,flag5=0,flag6=0,flag7=0,flag8=0,flag9=0;
            static HBRUSH brs;
            static HBITMAP hbmBuffer,hbmOldBuffer;
            static HINSTANCE hInstance;
            static POINTS maus;
            static POINT mauss;
    Sorry if its a mess, but I was just testing around, and I got tired of not figuring this out. Thanks.
    Attached Files Attached Files

  2. #2

    Thread Starter
    New Member
    Join Date
    Nov 2009
    Posts
    2

    Re: BitBlt Leak and error

    I figured I should be deleting the Solid Brushes.
    Right?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width