Out Of System Resources - TAdvToolButton

Some of my app users are getting an Out of System Resources exception occasionally.

It seems to be in relation to TAdvToolButton. Any ideas on tracking this down?

exception class    : EOutOfResources
exception message  : Out of system resources.

main thread ($f0c):
004f129f +02f xxx.exe Graphics       4327   +1 OutOfResources
004f1342 +07e xxx.exe Graphics       4353  +13 GDIError
004f1373 +007 xxx.exe Graphics       4358   +1 GDICheck
004f1564 +048 xxx.exe Graphics       4436   +4 TransparentStretchBlt
004f6446 +19e xxx.exe Graphics       8038  +39 TBitmap.Draw
004f0791 +095 xxx.exe Graphics       3839   +7 TCanvas.Draw
009cc25e +1da xxx.exe AdvToolBtn      633  +53 TAdvToolButton.DrawButtonGlyph
009ccb96 +04e xxx.exe AdvToolBtn      819   +4 TAdvToolButton.DrawButton
009cd993 +d53 xxx.exe AdvToolBtn     1084 +235 TAdvToolButton.Paint
004f0eee +016 xxx.exe Graphics       4118   +1 TCanvas.SetPenPos
00518a3d +061 xxx.exe Controls      13195   +7 TGraphicControl.WMPaint
0050f20c +2d4 xxx.exe Controls       7074  +91 TControl.WndProc
009cebd8 +050 xxx.exe AdvToolBtn     1623  +12 TAdvToolButton.WndProc
0050ee30 +024 xxx.exe Controls       6852  +10 TControl.Perform
00513f6a +18e xxx.exe Controls       9989  +27 TWinControl.PaintControls
00513d65 +131 xxx.exe Controls       9935  +24 TWinControl.PaintHandler
00514468 +048 xxx.exe Controls      10116   +6 TWinControl.WMPaint
005a356c +028 xxx.exe Forms          5547   +4 TCustomForm.WMPaint
0050f20c +2d4 xxx.exe Controls       7074  +91 TControl.WndProc
00513ad0 +568 xxx.exe Controls       9831 +144 TWinControl.WndProc
005a0930 +594 xxx.exe Forms          3961 +191 TCustomForm.WndProc
00513170 +02c xxx.exe Controls       9552   +3 TWinControl.MainWndProc
004cd330 +014 xxx.exe Classes       13491   +8 StdWndProc
777c273b +04b ntdll.dll                              KiUserCallbackDispatcher
757e5f35 +005 win32u.dll                             NtUserCallHwndLock
76860f51 +031 user32.dll                             UpdateWindow

Without knowing any further details, it is very hard to tell.

  1. Do you use the latest version of the components?
  2. How do you create & destroy TAdvToolButton and how do you create & destroy images used in the TAdvToolButton? Do you destroy always what you create?

Yes, the latest version of TMS components.

All of the buttons and images are set at design time.

It could well be that something else is chewing up resources and it happened to hang on the button repaint.

We would really need a sample source project with which we can reproduce this here to be able to investigate this.

I haven't even been able to reproduce the issue myself, but several users have sent in exception reports.

Not much more we can do for now.

I'm currently updating the enabled and disabled glyphs on a TAdvToolButton being used as a pause / resume button in response to actions happening elsewhere.

  BtPause.Glyph := nil;
  BtPause.GlyphDisabled := nil;
  if Paused then
  begin
    BtPause.Caption := 'Resume';
    ilTransport.GetBitmap(2, BtPause.Glyph);
    ilTransport.GetBitmap(3, BtPause.GlyphDisabled);
    BtPause.Enabled := True;
  end
  else
  begin
    BtPause.Caption := 'Pause';
    ilTransport.GetBitmap(0, BtPause.Glyph);
    ilTransport.GetBitmap(1, BtPause.GlyphDisabled);
    BtPause.Enabled := CanPause;
  end;

Is this an acceptable way to update the glyphs at runtime?

I cannot see something wrong with this approach.
Just from a performance perspective, it should not be needed to set Glyph, GlyphDisabled to nil as setting GlyphDisabled = nil will internally auto-generate the disabled glyph when you set a new glyph.

I'll have to check why I am setting the disabled glyph explicitly. It may have been that the automatic drawing if disabled didn't render well at the time but certainly worth revisiting.

I've just removed the manual setting of the disabled glyphs and it looks the same, so that simplifies the code somewhat. I can only think that I had issues with it at some point in time, possibly before it was updated to a TMS component. Thank for your help.