0

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

Screenshot

1

大陸北方網友
  • 3,696
  • 3
  • 12
  • 37
  • Can you post minimal code that reproduces the issue? – Zer0 Sep 11 '20 at 02:45
  • not really..... but its probably this... i think? https://pastebin.com/9jaqy0Df – user3564069 Sep 11 '20 at 03:27
  • 2
    `GC.KeepAlive()` is in the wrong place. This method preserves the object from the point it is declared from the point where `.KeepAlive()` is called. If you insert `.KeepAlive()` right after the object declaration, that's where the object becomes eligible for garbage collection. If you use a helper class to create the delegate, add `GC.KeepAlive()` in its destructor/finalizer (or `Dispose()` implementation) – Jimi Sep 11 '20 at 08:59
  • Thanks! :), that combined with a few other little changes has it working perfectly! :) thanks again! – user3564069 Sep 14 '20 at 04:37

0 Answers0