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.

What happens with CEF application on ENDSESSION?

Post Reply
rgdawson
Posts: 22
Joined: Tue Apr 10, 2018 11:05 pm

What happens with CEF application on ENDSESSION?

Post by rgdawson »

I was doing alot of restart testing of my app the other day and I got an Access Violation exception (not always, but occasionally) when restarting windows while my app was running.

The error seemed to be happening in DestroyGlobalCEFApp;

As we know, DestroyGlobalCEFApp is simply: if (GlobalCEFApp <> nil) then FreeAndNil(GlobalCEFApp);

My own app will repsond to WM_QUERYENDSESSION with Msg.Result := 0 ('No') and send itself a WM_CLOSE message in order to perform an orderly application close.

As a fix, I put DestroyGlobalCEFapp in a try..except block to suppress the exception and never saw the issue again, but that does not feel right.

I could not find any CEF4Delphi code related to WM_QUERYENDSESSION, but one theory I have is that CEF could be doing something, or maybe Windows is forcably killing the CEF app independently at the same time, and my call to FreeAndNil(GlobalCEFApp) sometimes causes an Access Violation.

R Greg Dawson
User avatar
salvadordf
Posts: 4074
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: What happens with CEF application on ENDSESSION?

Post by salvadordf »

Hi,

According to this page all applications should return true to respect the user's intention to close the session.
https://docs.microsoft.com/en-us/window ... endsession

After that you have a few seconds to close your application. It's recommended that your application doesn't show any user interface at this moment.

In our case, you would call TChromium.CloseBrowser(TRUE) to all the browsers to close them without questions but you still have to follow the destruction steps described in the demos.

Please, use the latest CEF4Delphi version because there was a shutdown issue in CEF a few months ago that might be the cause of that access violation.
Post Reply