Author Topic: gdi leak overflow on meatballs effect  (Read 930 times)

r0ger

  • Regular Member
  • *
  • Posts: 26
gdi leak overflow on meatballs effect
« on: November 14, 2021, 01:01:35 AM »
hi all ,

3 months ago i've ripped some aboutbox effect from a release, then i've noticed the GDI objects start to increase resulting in GDI leaking .
does it have to be the timer problem or is it just the font initialization causing this problem ?
r0ger // PRF

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: gdi leak overflow on meatballs effect
« Reply #1 on: November 14, 2021, 01:15:38 AM »
Hi roger, I don't have the time to do a full analysis but a quick look found SelectObject() but not reselecting the old object when finished and this will give you a GDI leak.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

fearless

  • Member
  • ****
  • Posts: 578
    • Github
Re: gdi leak overflow on meatballs effect
« Reply #2 on: November 14, 2021, 01:35:01 AM »
Every time AboutInit is called a new DC with a bitmap and font are created. Plus you are also creating solid brushes every time the about dialog is launched. None of these is cleaned up on exit.

Ideally you might create the brushes at start of the program and clean up on exit of program and save them to handles so they can be reused throughout the program. Or create at AboutInit of the about dialog, save handles and then clean up at end of dialog. Same goes with the DC and font created at AboutInit.
fearless

ASUS Crosshair 8 Hero, AMD 5950X, 32GB, MSI 5700XT, NZXT Kraken Z73, Seasonic 1000W PSU

Github Twitter Mastodon Gitbook

r0ger

  • Regular Member
  • *
  • Posts: 26
Re: gdi leak overflow on meatballs effect
« Reply #3 on: November 14, 2021, 03:22:21 AM »
fearless, thanx so much for your suggestion.

removed the solid brushes before the cmp [uMsgz],110h (initdialog) and now it doesn't cause GDI leaks.

Code: [Select]
invoke  CreateSolidBrush,0
mov     [hColor], eax

as of these codes below which i’ve removed from the beginning of AboutProc subroutine , if i had initiated the black brush only on WM_CTLCOLORDLG and then initialize with hColor variable , it still causes GDI leaks but only when you move the aboutbox.
so i now suggest this if you don't want to cause any GDI leaks nor when you move the dialog nor while the animation plays :

Code: [Select]
mov eax,[wParamz]
invoke SetBkColor,eax,Black
invoke GetStockObject,BLACK_BRUSH
ret

problem solved ! :thup:
« Last Edit: November 14, 2021, 12:52:32 PM by r0ger »
r0ger // PRF