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.

CefShutdown hangs

Post Reply
kewin.brand
Posts: 3
Joined: Thu Feb 22, 2018 12:11 pm

CefShutdown hangs

Post by kewin.brand »

Hi,

I'm having a problem with CEF4Delphi that happens when I close my application. I have a TChromium component that creates a browser that shows a static html, the problem is that when I close my program it hangs.
Debugging I saw that on the line -> if FMustShutDown then ShutDown;
Before closing the form I execute the following code: FChromium.CloseBrowser (True);
I think it's also valid to say that I use RunTime Packages.

Thank you.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: CefShutdown hangs

Post by salvadordf »

Hi Kewin,

Do you use the TChromium.Close and TChromiu.BeforeClose events after calling TChromium.CloseBrowser ?

What component are you using?
TChromium or TChromiumWindow?

Did you use a demo as a base for your app ? Which one ?
kewin.brand
Posts: 3
Joined: Thu Feb 22, 2018 12:11 pm

Re: CefShutdown hangs

Post by kewin.brand »

Hi,

Basically I have a TCustomControl with a TChromium encapsulated. I create my TCustomControl in the following way:

Code: Select all

FChromium: = TChromium.Create (Self);
...
FChromium.CreateBrowser (Self);
where "Self" is the CustomControl

in the destroy method of my CustomControl I do the following:

Code: Select all

begin
   if not (csDesigning in ComponentState) then
     FChromium.CloseBrowser (True);
   inherited;
end;
At the beginning of development I think i used the "MdiBrowser" demo.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: CefShutdown hangs

Post by salvadordf »

If TCustomControl is destroyed at the same time that you close your application then you may not need to call CloseBrowser at all.

However, if you create and destroy your TCustomControl manually at run time then you need to follow the destruction sequence described in the MDIBrowser demo.

Every TChildForm in the MDIBrowser follows this sequence :
  • FormCloseQuery calls TChromium.CloseBrowser which triggers TChromium.OnClose
  • TChromium.OnClose sends a CEFBROWSER_DESTROY message to destroy CEFWindowParent1 in the main thread which triggers TChromium.OnBeforeClose.
  • TChromium.OnBeforeClose sets FCanClose := True and sends WM_CLOSE to the child form.


The main form waits until all child forms are correctly closed before closing the app. If you miss any of these steps CEF won't be able to shut down correctly.

Other demos, like SimpleExternalPumpBrowser, also follow the same destruction sequence even if they don't destroy the browser at run time.
Post Reply