Page 1 of 1
CefShutdown hangs
Posted: Thu Feb 22, 2018 12:30 pm
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.
Re: CefShutdown hangs
Posted: Thu Feb 22, 2018 1:32 pm
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 ?
Re: CefShutdown hangs
Posted: Thu Feb 22, 2018 4:43 pm
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.
Re: CefShutdown hangs
Posted: Thu Feb 22, 2018 5:14 pm
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.