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.

How to debug CEF4Delphi?

User avatar
xpert13
Posts: 39
Joined: Wed May 31, 2017 5:26 pm

How to debug CEF4Delphi?

Post by xpert13 »

Hi.

Sometimes I have next exception in log file:

Code: Select all

[0924/172024.468:ERROR:CEF4Delphi(1)] TCefApplication.InitializeLibrary error : Access violation at address 0050CF76 in module 'chromium_client.exe'. Read of address 00000000
I want to understand why its happens. How can I debug CEF Delphi?
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to debug CEF4Delphi?

Post by salvadordf »

Hi,

There are some indications to debug CEF4Delphi applications in the 'Debugging' section of this web page :
https://www.briskbard.com/index.php?lang=en&pageid=cef

If the application stops inside Delphi code then it should be much easier to fix thanks to Delphi's call stack and the variable inspector.

However, If it stops inside a CEF DLL call then you can use the CEF debug symbols with the CEF debug binaries. You would need to use "WinDbg" or "Sysinternals Process Explorer" to get the call stack to find the last function that raised the exception.

In any case, you can always post in this forum a screen capture of the Delphi debugger, log copies, etc with the version of Delphi you are using and I'll take a look. Don't forget to say if you are running your app from a local hard drive or a networked unit.

It would be extremely useful to know if this error happens in the latest Delphi version too. The starter edition is free and you can install it in a matter of minutes.
thefunkyjoint
Posts: 513
Joined: Thu Aug 10, 2017 12:40 pm

Re: How to debug CEF4Delphi?

Post by thefunkyjoint »

I'm having some random AV too, and then my app crashes. How can i activate this 'log file' ?
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to debug CEF4Delphi?

Post by salvadordf »

Add uCEFConstants to the uses and set these properties in the DPR before the GlobalCEFApp.StartMainProcess call :

Code: Select all

  GlobalCEFApp.LogFile              := 'debug.log';
  GlobalCEFApp.LogSeverity          := LOGSEVERITY_ERROR; // use LOGSEVERITY_VERBOSE if you want more details
If you want to add custom error messages in the log use the CefLog or OutputDebugMessage functions from uCEFMiscFunctions.pas

Most of the times you will be getting those AVs because you need to close all the browsers properly before closing your app.
Check the code comments in the MDIBrowser demo.

If your app crashes too often and you had to kill it several times, you may need to delete the cache and cookies directories.
thefunkyjoint
Posts: 513
Joined: Thu Aug 10, 2017 12:40 pm

Re: How to debug CEF4Delphi?

Post by thefunkyjoint »

salvadordf wrote: Fri Oct 06, 2017 7:50 pm Add uCEFConstants to the uses and set these properties in the DPR before the GlobalCEFApp.StartMainProcess call :

Code: Select all

  GlobalCEFApp.LogFile              := 'debug.log';
  GlobalCEFApp.LogSeverity          := LOGSEVERITY_ERROR; // use LOGSEVERITY_VERBOSE if you want more details
If you want to add custom error messages in the log use the CefLog or OutputDebugMessage functions from uCEFMiscFunctions.pas

Most of the times you will be getting those AVs because you need to close all the browsers properly before closing your app.
Check the code comments in the MDIBrowser demo.

If your app crashes too often and you had to kill it several times, you may need to delete the cache and cookies directories.
Ok, will do it. In my tests the problem occurs most when i close my app and is triggered on this line :

GlobalCEFApp.Free;

Randomly my app will stop on this line and then freezes on 100% CPU until i force it to close in Task manager. I can see in my app's interface that the browser component disappears, but the app won't close.

Is there anything more i could do to diagnose this issue ?

Thanks !
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to debug CEF4Delphi?

Post by salvadordf »

Hi,

The most common cause of AV errors when you free GlobalCEFApp are unreleased interfaces.
Most of the times that's caused by browsers that were not closed properly but it could also be caused by other CEF interfaces created in your code.

The internal CEF3 structure is very complex and it's not always easy to find what interface is keeping some internal processes alive when you free GlobalCEFApp.

The MDIBrowser, ToolBoxBrowser and TabbedBrowser demos have all the code necessary to close each TChromium safely.

These are the code comments in the TabbedBrowser :

Code: Select all

// This is the destruction sequence when you remove a tab sheet:
// 1. RemoveTabBtnClick calls TChromium.CloseBrowser of the selected tab which triggers a TChromium.OnClose event.
// 2. TChromium.OnClose sends a CEFBROWSER_DESTROYWNDPARENT message to destroy TCEFWindowParent in the main thread which triggers a TChromium.OnBeforeClose event.
// 3. TChromium.OnBeforeClose sends a CEFBROWSER_DESTROYTAB message to destroy the tab in the main thread.
The MDIBrowser and ToolBoxBrowser demos wait for all the other child forms to be closed before closing the main form.

If you use the OSR mode you will even have to add a timer after the TChromium destruction before closing the main form.

As I said in my previous message, delete the cache and cookies directories before doing tests.
thefunkyjoint
Posts: 513
Joined: Thu Aug 10, 2017 12:40 pm

Re: How to debug CEF4Delphi?

Post by thefunkyjoint »

Hello Salvador,

Thanks for the hints.

My app usually has only one form opened when i close the app ; in this case i need to do something besides make sure there is no child forms opened ?

Another relevant info is that i usually create 3-4 TChromium in my apps, to do different things. Having multiple instances of TChromium could be a cause of issues ?
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to debug CEF4Delphi?

Post by salvadordf »

thefunkyjoint wrote: Sat Oct 07, 2017 2:58 pm My app usually has only one form opened when i close the app ; in this case i need to do something besides make sure there is no child forms opened ?
Another relevant info is that i usually create 3-4 TChromium in my apps, to do different things. Having multiple instances of TChromium could be a cause of issues ?
If you only have 1 TChromium in the main form, it's becoming rarer to get AV errors thanks to all the fixes made to CEF4Delphi with the help of all the forum members.

In your case, it's extremely important to close all the TChromium instances properly before closing your main form.

Please read the code comments in the DPR and PAS files from the previously mentioned demos.
Take a look at the creation and destruction sequences.
Use the demos as a base for your apps if necessary.
thefunkyjoint
Posts: 513
Joined: Thu Aug 10, 2017 12:40 pm

Re: How to debug CEF4Delphi?

Post by thefunkyjoint »

I'm still having this issue of the app does not close properly, but what is bothering more is some random AV and crashes of the app during its use, and this did not happen with DCEF3.

I'm activating the verbose logfile to try to find out something.

So far, thank you !
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to debug CEF4Delphi?

Post by salvadordf »

thefunkyjoint wrote: Sun Oct 08, 2017 12:48 pm I'm still having this issue of the app does not close properly, but what is bothering more is some random AV and crashes of the app during its use, and this did not happen with DCEF3.
I'm activating the verbose logfile to try to find out something.
Crashes during its use? That's very unusual.
Are they happening when you free one of the TChromium components?
Maybe a few seconds after you free one of the TChromium?

Try to open that website with this SimpleBrowser :
https://www.briskbard.com/SimpleBrowser.zip

Also try to open it with the official CEF3 Sample Application :
http://opensource.spotify.com/cefbuilds ... nt.tar.bz2
Post Reply