1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-11-23 21:34:53 +02:00

Workaround for issue #529. The PopupBrowser demo for Lazarus in Windows crashes at shutdown with CEF 128

This commit is contained in:
Salvador Díaz Fau
2025-10-08 13:37:19 +02:00
parent c45521d416
commit 22a7a2f7b6
5 changed files with 43 additions and 21 deletions

View File

@@ -59,4 +59,10 @@ object ChildForm: TChildForm
Left = 24
Top = 56
end
object Timer1: TTimer
Enabled = False
OnTimer = Timer1Timer
Left = 127
Top = 70
end
end

View File

@@ -22,6 +22,9 @@ type
TChildForm = class(TForm)
chrmosr: TChromium;
Panel1: TBufferPanel;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure Panel1Enter(Sender: TObject);
procedure Panel1Exit(Sender: TObject);
@@ -124,7 +127,7 @@ function TChildForm.CreateClientHandler(var windowInfo : TCefWindowInfo;
var client : ICefClient;
const targetFrameName : ustring;
const popupFeatures : TCefPopupFeatures) : boolean;
begin
begin
Panel1.CreateIMEHandler;
chrmosr.InitializeDragAndDrop(Panel1);
@@ -149,8 +152,8 @@ end;
procedure TChildForm.chrmosrBeforeClose(Sender: TObject; const browser: ICefBrowser);
begin
FCanClose := True;
PostMessage(Handle, WM_CLOSE, 0, 0);
FCanClose := True;
Timer1.Enabled := True; // Workaround for an access violation in CallDefaultWindowProc (win32callback.inc)
end;
procedure TChildForm.Panel1UTF8KeyPress(Sender: TObject; var UTF8Key: TUTF8Char);
@@ -560,14 +563,15 @@ end;
procedure TChildForm.FormCreate(Sender: TObject);
begin
FPopUpBitmap := nil;
FPopUpRect := rect(0, 0, 0, 0);
FShowPopUp := False;
FResizing := False;
FPendingResize := False;
FCanClose := False;
FClosing := False;
FResizeCS := TCriticalSection.Create;
FPopUpBitmap := nil;
FPopUpRect := rect(0, 0, 0, 0);
FShowPopUp := False;
FResizing := False;
FPendingResize := False;
FCanClose := False;
FClosing := False;
FClientInitialized := False;
FResizeCS := TCriticalSection.Create;
InitializeLastClick;
end;
@@ -580,7 +584,7 @@ begin
if (FResizeCS <> nil) then FreeAndNil(FResizeCS);
if FClientInitialized and MainForm.HandleAllocated then
PostMessage(MainForm.Handle, CEF_CHILDDESTROYED, 0, 0);
PostMessage(MainForm.Handle, CEF_CHILDDESTROYED, Tag, 0);
end;
procedure TChildForm.FormHide(Sender: TObject);
@@ -761,6 +765,12 @@ begin
Result := (targetDisposition in [CEF_WOD_NEW_FOREGROUND_TAB, CEF_WOD_NEW_BACKGROUND_TAB, CEF_WOD_NEW_POPUP, CEF_WOD_NEW_WINDOW]);
end;
procedure TChildForm.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := False;
PostMessage(Handle, WM_CLOSE, 0, 0);
end;
procedure TChildForm.chrmosrCanFocus(Sender: TObject);
begin
// The browser required some time to create associated internal objects

View File

@@ -11,6 +11,7 @@ object MainForm: TMainForm
Font.Height = -11
Font.Name = 'Tahoma'
Position = poScreenCenter
LCLVersion = '4.2.0.0'
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
OnDestroy = FormDestroy

View File

@@ -12,7 +12,7 @@ uses
const
CEF_CREATENEXTCHILD = WM_APP + $A50;
CEF_CHILDDESTROYED = WM_APP + $A51;
CEF_CHILDDESTROYED = WM_APP + $A51;
type
@@ -140,6 +140,7 @@ end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
FChildForm := nil;
FClosingChildren := False;
FClosingMainForm := False;
FCanClose := False;
@@ -260,9 +261,9 @@ begin
else
FChildCounter := 1;
FChildForm := TChildForm.Create(self);
FChildForm.Name := 'ChildForm_' + IntToStr(FChildCounter);
FChildForm.Tag := FChildCounter;
FChildForm := TChildForm.Create(self);
FChildForm.Name := 'ChildForm_' + IntToStr(FChildCounter);
FChildForm.Tag := FChildCounter;
end;
procedure TMainForm.BrowserCreatedMsg(var aMessage : TMessage);
@@ -336,28 +337,32 @@ procedure TMainForm.WMMove(var aMessage : TWMMove);
begin
inherited;
if (Chromium1 <> nil) then Chromium1.NotifyMoveOrResizeStarted;
if (Chromium1 <> nil) then
Chromium1.NotifyMoveOrResizeStarted;
end;
procedure TMainForm.WMMoving(var aMessage : TMessage);
begin
inherited;
if (Chromium1 <> nil) then Chromium1.NotifyMoveOrResizeStarted;
if (Chromium1 <> nil) then
Chromium1.NotifyMoveOrResizeStarted;
end;
procedure TMainForm.WMEnterMenuLoop(var aMessage: TMessage);
begin
inherited;
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := True;
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then
GlobalCEFApp.OsmodalLoop := True;
end;
procedure TMainForm.WMExitMenuLoop(var aMessage: TMessage);
begin
inherited;
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := False;
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then
GlobalCEFApp.OsmodalLoop := False;
end;
end.

View File

@@ -2,7 +2,7 @@
"UpdateLazPackages" : [
{
"ForceNotify" : true,
"InternalVersion" : 795,
"InternalVersion" : 796,
"Name" : "cef4delphi_lazarus.lpk",
"Version" : "140.1.14"
}