Nach 30 sek. Absturz
-
wow, er hat mir das Programm zugeschickt. 100 % Systemauslastung beim nichtstun und ein derpes GDI-Leak. Jede Sekunde 25 neue GDI Objekte.
-
krass.
-
GDI hört sich nach WinApi an.
Thread verschoben ins WinApi Forum. WinAPI
-
Original erstellt von <DasChecker>:
wow, er hat mir das Programm zugeschickt. 100 % Systemauslastung beim nichtstun und ein derpes GDI-Leak. Jede Sekunde 25 neue GDI Objekte.Das findest du toll, was? So tun, als ob du anderen helfen willst, und dann denjenigen im Forum vor allen fertig machen, wie?! Das macht dich geil, oder?
-
Was hast du denn auf einmal? Sein Quelltext ist ziemlich groß und ich habe keine Lust den Fehler für ihn zu finden. Das macht er bestimmt auch lieber selber. Und was hat das mit fertig machen zu tun?
-
@Timm: Du kannst ja etwas Code posten, wenn du willst. Die WM_PAINT wär sicherlich interessant
(oder halt da, wo du deine ganzen Sachen zeichnest ;)).
cya
-
und am besten noch wo du auf die pfeiltasten reagierst..
-
Vielleicht auch noch das Laden/Löschen der Bitmaps.
cya
-
Ach am besten den ganzen Code. *g*
-
@*g*: Hast eigentlich Recht
cya
-
Hi,
Ich schätze das es an diesen beiden Funktionen liegt, denn die sind für die Figur zuständig, und die Figur verändert sich beim spielen ja auch:void TransparentBlit(HDC hdc, int destX, int destY, int destWidth, int destHeight, HDC hdc2, int srcX, int srcY, UINT tranparency) { unsigned char* pImageBits = NULL; unsigned char* pBackBits = NULL; BITMAPINFO bmBitmapInfo = {0}; HBITMAP hBitmap, hBitmap2, hOldBitmap, hOldBitmap2; HDC compHDC; HDC compHDC2; // Fill in our BitmapInfo structure (we want a 24 bit image) bmBitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmBitmapInfo.bmiHeader.biCompression = BI_RGB; bmBitmapInfo.bmiHeader.biHeight = destHeight; bmBitmapInfo.bmiHeader.biWidth = destWidth; bmBitmapInfo.bmiHeader.biBitCount = 24; bmBitmapInfo.bmiHeader.biClrUsed = 0; bmBitmapInfo.bmiHeader.biPlanes = 1; // Create 2 DIB Sections. One for the Front Buffer and one for the BackBuffer hBitmap = CreateDIBSection(hdc, &bmBitmapInfo, DIB_RGB_COLORS,(void **)&pImageBits, 0,0); hBitmap2 = CreateDIBSection(hdc, &bmBitmapInfo, DIB_RGB_COLORS,(void **)&pBackBits, 0,0); // Create a compatible DC for the front buffer and Select our Dib Section into it compHDC = CreateCompatibleDC(hdc); hOldBitmap = (HBITMAP)SelectObject(compHDC, hBitmap); // Create a compatible DC for the back buffer and Select our Dib Section into it compHDC2 = CreateCompatibleDC(hdc2); hOldBitmap2 = (HBITMAP)SelectObject(compHDC2, hBitmap2); // Blit the front buffer to our compatible DC that will hold the destination bits BitBlt(compHDC, 0, 0, destWidth, destHeight, hdc, destX, destY, SRCCOPY); // Blit the back buffer to our compatible DC that will hold the source bits BitBlt(compHDC2, 0, 0, destWidth, destHeight, hdc2, srcX, srcY, SRCCOPY); // Loop through the 24 bit image (Times 3 for R G and B) for(int i = 0; i < destHeight * destWidth * 3; i += 3) { // Check if the current pixel being examined isn't the transparent color // Remember, the image bits are stored (Blue, Green, Red), not (Red, Green, Blue) // We use the system macros to abstract the R G B data if((pBackBits[i] != GetBValue(tranparency)) || (pBackBits[i+1] != GetGValue(tranparency)) || (pBackBits[i+2] != GetRValue(tranparency))) { // Assign the desired pixel to the foreground pImageBits[i] = pBackBits[i]; pImageBits[i + 1] = pBackBits[i + 1]; pImageBits[i + 2] = pBackBits[i + 2]; } } // Blit the transparent image to the front buffer (Voila!) BitBlt(hdc, destX, destY, destWidth, destHeight, compHDC, 0, 0, SRCCOPY); // Cleanup the monochrome bitmaps SelectObject(compHDC, hOldBitmap); SelectObject(compHDC2, hOldBitmap2); // Free GDI Resources DeleteObject(hBitmap); DeleteObject(hBitmap2); DeleteDC(compHDC); DeleteDC(compHDC2); } ////////////////////////////////////////////////////////////////////////// ///// ///// FUNCTION: DisplayTransparentBitmap() ///// DESCRIPTION: This takes a portion of a bitmap and puts it in the backbuffer ///// BUT, not displaying any color with rgb values of (0, 0, 0). ///// The problem with this function is that is leaks memory in Win98 ///// INPUT: hBitmap - The handle to the bitmap to display ///// x, y - The X and Y coordinates to display the bitmap ///// rPortion - The portion of the bitmap to be displayed ///// OUTPUT: pBuffer - The back buffer that holds the buffer information ///// RETURN: nothing ///// ////////////////////////////////////////////////////////////////////////// void DisplayTransparentBitmap(BUFFER *pBuffer, HBITMAP hBitmap, int x, int y, RECT rPortion) { // Assign the width and height to shorten variables. int width = rPortion.right - rPortion.left, height = rPortion.bottom - rPortion.top; // Select the bitmap handle into the extra hdc that holds the bitmap HBITMAP hOldBitmap = (HBITMAP) SelectObject(pBuffer->hdcBitmap, hBitmap); // Blit the bitmap hdc into the backbuffer using the transparent color 0 (black) TransparentBlit(pBuffer->hdcBack, x, y, width, height, pBuffer->hdcBitmap, rPortion.left, rPortion.top, TRANSPARENT_COLOR); // Select the old handle to the bitmap back where it was to clean up SelectObject(pBuffer->hdcBitmap, hOldBitmap); }
Der ganze Code ist viel zu groß, deshalb poste ich ihn hier erstmal nicht.
-
Sorry, für diesen sinnlosen Post
Ich hab den Fehler gefunden:// --Vorher-- switch(tile) { case WALL: // Load a wall tile into this index DisplayBitmap(&g_Buffer,LoadABitmap("wall.bmp")/*Hier der Fehler*/,0,TILE_WIDTH*15); break; //... } /////////////////// // --Nachher HBITMAP temp; switch(tile) { case WALL: // Load a wall tile into this index DisplayBitmap(&g_Buffer,temp = LoadABitmap("wall.bmp"),0,TILE_WIDTH*15); break; //... } DeleteObject(temp);
So ist es richtig
[ Dieser Beitrag wurde am 11.01.2003 um 16:30 Uhr von Timm editiert. ]
-
Warum lädst du nicht jedes Bitmap einmal am Anfang des Programms bzw. Levels und löscht es dann beim Beenden? Ist doch viel zu langsam das jedesmal neu zu laden.