CEF4Delphi crash 0xE0000008 kernelbase.dll

Post Reply
nimq
Posts: 6
Joined: Thu May 09, 2019 10:11 pm

CEF4Delphi crash 0xE0000008 kernelbase.dll

Post by nimq » Thu May 09, 2019 10:51 pm

Greetings!

Faced a crash of CEF4Delphi when closing an app - 0xE0000008 kernelbase.dll.

To demonstrate the bug, I took CEF4Delphi\demos\CustomResourceBrowser and added thread with the following code

Code: Select all

  tm := GetTickCount;

  while not Terminated do
  begin
    if GetTickCount - tm > 15000 then
    begin
      //MainForm.Close;
      Synchronize(Close);
      exit;
    end;
    Sleep(300);
  end;
Because the bug is not stable, i wrote loader that lounches the demo app from the directory, waits for it to close and restarts in a loop. I created 10 directories with the executable and launched all the instances simultaniously. In 2-3 minutes after the start APPCRASH appears.

The question is - am I closing CEF4 correctly? Could the problem be due to the fact that all running programs from different directories have some common global objects?

Thanks!

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

Re: CEF4Delphi crash 0xE0000008 kernelbase.dll

Post by salvadordf » Fri May 10, 2019 7:59 am

Hi,

You need to follow the destruction sequence described in the code comments inside the demo you used as a template for your app.

In this case CustomResourceBrowser needs to be closed following these steps :
  • The FormCloseQuery event sets CanClose to False and calls TChromiumWindow.CloseBrowser, which triggers the TChromiumWindow.OnClose event.
  • The TChromiumWindow.OnClose event calls TChromiumWindow.DestroyChildWindow which triggers the TChromiumWindow.OnBeforeClose event.
  • TChromiumWindow.OnBeforeClose sets FCanClose to True and closes the form.
If you need several browsers in one application use these demos : ToolBoxBrowser, MDIBrowser or TabbedBrowser.
They close all the browsers correctly before closing the main form.

nimq
Posts: 6
Joined: Thu May 09, 2019 10:11 pm

Re: CEF4Delphi crash 0xE0000008 kernelbase.dll

Post by nimq » Fri May 10, 2019 1:13 pm

Hi,

Yes, there are all this steps in CustomResourceBrowser\uMainForm.pas, I added only two lines to Chromium_OnAfterCreated proc

Code: Select all

  ChromiumWindow1.LoadURL('https://microsoft.com');
  TControlThread.Create();
now I have changed close method in my thread to

Code: Select all

  PostMessage(MainForm.Handle, WM_CLOSE, 0, 0);
I call it 15 sec after the start

When I debug the app all this steps executed:

Code: Select all

1. FormCloseQuery CanClose = false
2. FormCloseQuery ChromiumWindow1.CloseBrowser(True);
3. OnClose  
    if not(ChromiumWindow1.DestroyChildWindow) then
      begin
        FCanClose := True;
        Close;
      end;
But sometimes appcrash appear anyway (

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

Re: CEF4Delphi crash 0xE0000008 kernelbase.dll

Post by salvadordf » Fri May 10, 2019 2:15 pm

I searched for this error code and I found these pages from other CEF wrappers and the main CEF project :
https://github.com/cefsharp/CefSharp/issues/2019
https://github.com/cefsharp/CefSharp/issues/2255
https://magpcss.org/ceforum/viewtopic.php?f=6&t=15120
https://magpcss.org/ceforum/viewtopic.php?f=6&t=16598&start=0

I also found some pages giving the same error code while using Chrome and the Chromium issues list has these unresolved issues with that error code :
https://bugs.chromium.org/p/chromium/issues/detail?id=913909&q=e0000008&colspec=ID%20Pri%20M%20Stars%20ReleaseBlock%20Component%20Status%20Owner%20Summary%20OS%20Modified
https://bugs.chromium.org/p/chromium/issues/detail?id=664808&q=e0000008&colspec=ID%20Pri%20M%20Stars%20ReleaseBlock%20Component%20Status%20Owner%20Summary%20OS%20Modified

CustomResourceBrowser already has the IMAGE_FILE_LARGE_ADDRESS_AWARE flag to handle more than 2GB per process and it uses "in-memory" cache.
If you use "in-memory" cache CEF will create a directory inside %LocalAppData% called CEF to store some user settings and all the CustomResourceBrowser copies will use it.

I've never seen that issue in my computers but this seems to be a memory allocation issue inside Chromium.

I can only suggest you try building the demo in 64 bits.

nimq
Posts: 6
Joined: Thu May 09, 2019 10:11 pm

Re: CEF4Delphi crash 0xE0000008 kernelbase.dll

Post by nimq » Fri May 17, 2019 10:44 pm

Hello!

Thanks for your reseach!

1. I tried to disable "im-memory" cache and build for x64 - the problem remain
2. I tried to build cefsimple.exe x64 and run the same test - the problem doesnt reproduce

So, in this case, I presume that the problem is on cef4delphi side..
Could I send you the project for reproduce the bug?

Thanks!

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

Re: CEF4Delphi crash 0xE0000008 kernelbase.dll

Post by salvadordf » Sat May 18, 2019 7:37 am

Please, post a link to the source files that reproduces that issue.

Thanks!

nimq
Posts: 6
Joined: Thu May 09, 2019 10:11 pm

Re: CEF4Delphi crash 0xE0000008 kernelbase.dll

Post by nimq » Sun May 19, 2019 2:55 pm

Hello!

All necessary files https://www.sendspace.com/file/pbwbr0

---
Instruction for reproducing 0xE0000008 APPCRASH KernelBase.dll

1. Build CRBrowser.exe and copy it to %test_dir%\1 directory along with cef.binary files
2. Build loader.exe and copy it to %test_dir%\1 directory
3. Make 9 copies of catalog 1 - 2,3,4,5,6,7,8,9,10
4. Copy start_test.bat and kill.bat files to %test_dir%
5. It is necessary to change %test_dir% in the start_test.bat file to the correct directory
6. Run start_test.bat, 10 loader.exe should start, which will run CRBrowser.exe in a loop

An error 0xE0000008 will appear in kernelbase.dll within 5-30 minutes
---

Thanks!

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

Re: CEF4Delphi crash 0xE0000008 kernelbase.dll

Post by salvadordf » Wed May 22, 2019 7:09 am

Thanks for the sources!
I'll try to test them as soon as I can.

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

Re: CEF4Delphi crash 0xE0000008 kernelbase.dll

Post by salvadordf » Wed May 22, 2019 8:40 pm

I did a quick test but I closed it immediately because I don't want to be blacklisted by the owners of the test website.
That demo is a stress test for the browser, your operating system and the test website.

There are several suggestions :
  • Check the memory usage if you open so many browsers at the same time. If you run out of RAM or Windows runs out of resources you will get all kinds of weird errors.
  • If you need to open several browsers use one application. The MDIBrowser demo has all the code if you need multiple browsers with independent cache.
  • Use GlobalCEFApp.DeleteCache to delete the cache before CEF is initialized.

Post Reply