Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.
This is an elusive bug that only happens in some occasions.
It's difficult to replicate with the demos and even more difficult to catch in a debugger.
I did a lot of tests with the demos but I didn't test it on new apps without browsers.
Your report makes me think that the bug is present in the classes used by GlobalCEFApp to initialize and finalize CEF, which rules out all other theories about TChromium destruction, etc.
Some users reported shutdown problems that can be avoided if "FreeLibrary" is not called. I added the GlobalCEFApp.MustFreeLibrary property to skip the FreeLibrary call when GlobalCEFApp is destroyed.
Some more suggestions to avoid shutdown problems :
Follow the "destruction sequence" described in the code comments found in many demos. Delay your app destruction until ALL your browsers received the TChromium.OnBeforeClose event.
The GlobalCEFApp destruction should be the last code line in the DPR. This is even more important if your app has a complex destruction. In some cases, freeing all our forms before destroying GlobalCEFApp can help too.
Are there any disadvantages to MustFreeLibrary := False? I have had this problem (~5% of the time) despite following the shutdown sequence patterns. I just realized I should try MustFreeLibrary := False. Since doing this I have not seen any shutdown errors, but I am wondering if there is any reason to ever let MustFreeLibrary := True?
Setting GlobalCEFApp.MustFreeLibrary to FALSE forces CEF4Delphi to skip the FreeLibrary call when GlobalCEFApp is destroyed.
I always use LoadLibrary (or LoadLibraryEx) with FreeLibrary to decrement the library's reference count but Windows also unloads the module when the process terminates.
I found several web pages reporting access violations when they try to call FreeLibrary in Delphi applications.