locked
Glass control "CallbackOnCollectedDelegate" issue RRS feed

  • Question

  • Hi guys!

    So ive been working on a glass class that I found online and have modified the drawing of the controls to look smoother on the windows 10 glass controls. It works great until I open multiple windows, after the 3rd window is opened the program crashes.

    Managed Debugging Assistant 'CallbackOnCollectedDelegate' : 'A callback was made on a garbage collected delegate of type 'BlurTest!WinUtils.WinAPI+WndProcDelegate::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.'

    I have included the source and a image of the glass form, to replicate my issue:
    I compile the code from the zip and click on the open new window button once to make a new window.
    the program is stable. but once I open another 2 windows it always crashes with the above error.

    any help would be greatly appreciated guys :) thanks!

    Project:
    https://mega.nz/file/BZkhDBhK#ivaeAfQMV_PyDSX_GTieo3CKbpzQ9ebJ3XsbB2YkeOo


    Friday, September 11, 2020 2:37 AM

Answers

  • Try this minimal fix for LayeredWindowHelper. Replace ‘static’ with ‘readonly’ and modify the constructor:

    private readonly WinAPI.WndProcDelegate m_CtrlWndProcDelegate;

    . . .

    public LayeredWindowHelper( Form host )

    {

           this.host = host;

           host.Tag = this;

           m_CtrlWndProcDelegate = CtrlWndProc;

           HookChildControl( host );

           RefreshCtrl( );

    }


    It assumes that Tag will not be used for other purposes.

    But probably the implementation can be optimised with more changes.

    Friday, September 11, 2020 7:54 AM

All replies

  • Try this minimal fix for LayeredWindowHelper. Replace ‘static’ with ‘readonly’ and modify the constructor:

    private readonly WinAPI.WndProcDelegate m_CtrlWndProcDelegate;

    . . .

    public LayeredWindowHelper( Form host )

    {

           this.host = host;

           host.Tag = this;

           m_CtrlWndProcDelegate = CtrlWndProc;

           HookChildControl( host );

           RefreshCtrl( );

    }


    It assumes that Tag will not be used for other purposes.

    But probably the implementation can be optimised with more changes.

    Friday, September 11, 2020 7:54 AM
  • Sweet looks like its working :), ill let it run for an hour with 8 windows open and if it doesnt crash ill mark it as answered :) thanks mate your a legend :)
    Friday, September 11, 2020 8:14 AM