-
Aug 6th, 2024, 08:24 PM
#1
Thread Starter
Member
[RESOLVED] StretchDIBits Memory Leak??
Hello all! I have code to retrieve a byte array from winsock and then I call StretchDIBits to take byte array into DC of my DIB section. I have never used StretchDIBits, only GetDIBits. After this, I BitBlt the DC onto Form1.
However, when I run the code, a big memory leak occurs! (up to 1.8 GB!!) I commented out StretchDIBits call and it did not leak.
Here is the code for Winsock_DataArrival
Code:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Winsock1.GetData RecvBMP
StretchDIBits BufferDC, 0, 0, Form1.ScaleWidth, Form1.ScaleHeight, 0, 0, 1280, 768, RecvBMP(6), bi24BitInfo, 0, vbSrcCopy
'Draw buffer to form DC
BitBlt Form1.hDC, 0, 0, Form1.ScaleWidth, Form1.ScaleHeight, BufferDC, 0, 0, vbSrcCopy
End Sub
Thanks in advance!!!
No, Shaggy Hiker, I am not stealing your signature.
-
Aug 6th, 2024, 09:04 PM
#2
Re: StretchDIBits Memory Leak??
Probably you need to switch the form's ScaleMode to pixels or otherwise convert twips to pixels before passing the values to "StretchDIBits".
Also you don't need a BufferDC, you could put it directly onto the form's hDC.
If the source and destination rectangles are wildly different, you can obtain a higher quality stretching with:
Code:
Private Declare Function SetStretchBltMode Lib "gdi32" (ByVal hDC As Long, ByVal nStretchMode As Long) As Long
Private Const HALFTONE As Long = 4
SetStretchBltMode Form1.hDC, HALFTONE
Last edited by VanGoghGaming; Aug 6th, 2024 at 09:27 PM.
-
Aug 6th, 2024, 09:36 PM
#3
Re: StretchDIBits Memory Leak??
You didn't provide more details about your "RecvBMP" array and what does it contain but since you seem to use a "bi24BitInfo" structure you need to add padding to the array's width if it's not a multiple of 4.
-
Aug 7th, 2024, 06:28 AM
#4
Thread Starter
Member
Re: StretchDIBits Memory Leak??
Originally Posted by VanGoghGaming
Probably you need to switch the form's ScaleMode to pixels or otherwise convert twips to pixels before passing the values to "StretchDIBits".
Also you don't need a BufferDC, you could put it directly onto the form's hDC.
If the source and destination rectangles are wildly different, you can obtain a higher quality stretching with:
Code:
Private Declare Function SetStretchBltMode Lib "gdi32" (ByVal hDC As Long, ByVal nStretchMode As Long) As Long
Private Const HALFTONE As Long = 4
SetStretchBltMode Form1.hDC, HALFTONE
Thanks. I will check when I can but I believe I have set ScaleMode to pixels, and I know that I am passing ScaleWidth and ScaleHeight. What would I pass for BITMAPINFO parameter of StretchDIBits if I am placing it directly onto the form?
No, Shaggy Hiker, I am not stealing your signature.
-
Aug 7th, 2024, 06:58 AM
#5
Thread Starter
Member
Re: StretchDIBits Memory Leak??
Originally Posted by VanGoghGaming
You didn't provide more details about your "RecvBMP" array and what does it contain but since you seem to use a "bi24BitInfo" structure you need to add padding to the array's width if it's not a multiple of 4.
I think the problem may be in the padding.
Sender calls GetDIBits to put it into SendBMP. the first 6 bytes are 4 bytes for length descriptor, and 2 to indentify what kind of data it is. To make room for these, I put SendBMP(6) for lpBits parameter. GetDIBits seems to be fine. However, it is true that I think I padded array size, then added 6 to it AFTER the padding, so it was 2 bytes off.
I wonder if the missing 2 bytes in the array is what is causing StretchDIBits to leak? (even though I put RecvBMP(6) for the lpBits parameter)
No, Shaggy Hiker, I am not stealing your signature.
-
Aug 7th, 2024, 08:13 AM
#6
Thread Starter
Member
Re: StretchDIBits Memory Leak??
OK, I fixed the issue with 4 byte. It no longer leaks but now I have to make code for accounting that it does not all arrive in one piece. Will report back later if it works
No, Shaggy Hiker, I am not stealing your signature.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|