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.

Chromium crashes after parent changes

Post Reply
Albus

Chromium crashes after parent changes

Post by Albus »

Hi,
I have a frame with a panel in it and a CEFWindowParent in the panel. At first I create a browser with Chromium.CreateBrowser, this works fine. But now I change the Parent of the Frame and in this moment this chromium crashes. I make just this:

Code: Select all

Form.Parent := newParent;
Form.Visible := True;
The content of the Form is this:

Code: Select all

TForm
 (|- TChromium)
  |- TPanel
      |- TCEFWindowParent
I don't think that's supposed to happen.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Chromium crashes after parent changes

Post by salvadordf »

Try creating a new CEFWindowParent (let's call it NewCEFWindowParent) and using TChromium.SetNewBrowserParent(NewCEFWindowParent.Handle);
Albus

Re: Chromium crashes after parent changes

Post by Albus »

Hi, this doesn't worked. The chromium process crashed anyway.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Chromium crashes after parent changes

Post by salvadordf »

I did a quick test modifying the SimpleBrowser2 to include 2 frames, each with a panel and a CEFWindowParent.
The structure would be like this :
  • Frame1 -> Panel -> CEFWindowParent1
  • Frame2 -> Panel -> CEFWindowParent2
I also added 2 buttons :
  • Button1 : Calls SetNewBrowserParent to switch the browser parent between CEFWindowParent1 and CEFWindowParent2.
  • Button2 : Sets Frame1.parent to a different component.
If I click Button2 while CEFWindowParent1 is the browser parent causes problems. I'm not sure if Delphi destroys CEFWindowParent1 or recreates its handle.

SimpleBrowser2 still has the code to close the app correctly following the destruction sequence and the CEFWindowParent1 destruction triggers TChromium.BeforeClose, closing the application.

This can be avoided following these steps :
  • First click Button1 to set CEFWindowParent2 as the new browser parent.
  • Then click Button2 to set the new Frame1 parent.
  • Then click Button1 again to set CEFWindowParent1 as the browser parent.
Albus

Re: Chromium crashes after parent changes

Post by Albus »

This solution is quite complicated. We have now solved it in such a way that we recreate the browser after the parent change. Since the browser was invisible before, the user does not notice the difference afterwards.
Albus

Re: Chromium crashes after parent changes

Post by Albus »

Hi, after we have rebuilt a bit, our previous workaround doesn't work anymore. So I've now implemented your solution and move the browser to another WindowParent during the parent change. Basically this works fine. Now, however, the WindowParent has different dimensions after the parent change. However, the browser does not render itself again directly when it is moved to a new WindowParent. Now we have grey bars on the right side and a part of the browser is cut off. As soon as you change the window size manually, the browser renders itself again and everything fits.
Is there a way to trigger new rendering by code?
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Chromium crashes after parent changes

Post by salvadordf »

Use TCEFWindowParent.UpdateSize;
Post Reply