App crash on close - using DBGrid/DBNavigator

Post Reply
dwcef21
Posts: 4
Joined: Tue Jun 15, 2021 1:16 pm

App crash on close - using DBGrid/DBNavigator

Post by dwcef21 »

Using DBGrid or DBNavigator in an App results in a crash (0xc0000005) when closing the app. Just placing one of these components on the main form leads to the error.

WIN 10 64 bit
CEF 90.6.7
Delphi 10.4.2
32-bit version of SimpleBrowser demo

further information:

Use of class constructor and FButtonsImageCollection used by tDBGrid/tDBNavigator triggers the problem. Using the following code in the demo the app crashes as well.

Code: Select all

interface

uses ...,Vcl.ImageCollection;

type
  TForm1 = class(TForm)
    ChromiumWindow1: TChromiumWindow;
    ...
   end; 

tClassConstructorTest = class(TObject)
    class var FButtonsImageCollection: TImageCollection;
    class constructor Create;
    class destructor Destroy;
  end;

implementation

uses
  uCEFApplication, vcl.DBCtrls;
  
  { tClassConstructorTest }

class constructor tClassConstructorTest.Create;
  procedure InitButtonsImageCollection;
  begin
    FButtonsImageCollection := TImageCollection.Create(nil);
    FButtonsImageCollection.Add('FIRST', HInstance,  'DBN_' + 'FIRST', ['', '_20X']);       //this line triggers the problem
  end;

begin
  InitButtonsImageCollection;
end;

class destructor tClassConstructorTest.Destroy;
begin
  FreeAndNil(FButtonsImageCollection);
end;

...

procedure TForm1.FormCreate(Sender: TObject);
var
  IntCCT: tClassConstructorTest;
begin
  FCanClose := False;
  FClosing  := False;
  IntCCT := tClassConstructorTest.Create;
  FreeAndNil(IntCCT);
  // The browser will load the URL in AddressEdt initially.
end;

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

Re: App crash on close - using DBGrid/DBNavigator

Post by salvadordf »

Hi,

Check that your application follows the destruction steps described in the demo you used as a template for your app.

Class constructors and destructors are executed in the unit initialization and finalization. At first glance I don't see any problem with your code but you have to be careful because the unit initialization is executed before the CEF initialization and the unit finalization is executed after the CEF destruction.
dwcef21
Posts: 4
Joined: Tue Jun 15, 2021 1:16 pm

Re: App crash on close - using DBGrid/DBNavigator

Post by dwcef21 »

Hi,

the posted code is an addition to the SimpleBrowser-demo. Adding tClassConstructorTest to that demo and creating an instance in TForm1.FormCreate triggers the crash.

Same problem occurs if i place a DBGrid/DBNavigator component on the main form of that demo. No other changes in the code.

The class constructor is not the problem by itself. Using

Code: Select all

FButtonsImageCollection.Add('FIRST', HInstance,  'DBN_' + 'FIRST', ['', '_20X']);
in a class constructor is the problem. But this is code of the vcl.
User avatar
salvadordf
Posts: 3067
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: App crash on close - using DBGrid/DBNavigator

Post by salvadordf »

I added a DBGrid and a DBNavigator component to the SimpleBrowser demo and I couldn't reproduce the crash.

CEF uses multiple processes and Delphi executes the initialization and finalization sections of all the units in the uses section in all of those processes. If the initialization or finalization sections are too complex or they require exclusive access to some files/devices/databases then anything can happen.

In these cases it's recommended using a different executable for the CEF subprocesses. See the SubProcess demo.
dwcef21
Posts: 4
Joined: Tue Jun 15, 2021 1:16 pm

Re: App crash on close - using DBGrid/DBNavigator

Post by dwcef21 »

Hi,

thanks for looking into this. A colleague advised me to be more precise. Crashing is one of the background processes. werfault.exe starts sends its data and an entry into windows event viewer (application) is generated. Then the demo closes. The demo itself shows no error message.
User avatar
salvadordf
Posts: 3067
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: App crash on close - using DBGrid/DBNavigator

Post by salvadordf »

This information suggests that you need to use a different EXE for the subprocesses.
dwcef21
Posts: 4
Joined: Tue Jun 15, 2021 1:16 pm

Re: App crash on close - using DBGrid/DBNavigator

Post by dwcef21 »

Hi,

i will try this. Thanks for the input.
Post Reply