You've already forked CEF4Delphi
mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-07-12 22:30:17 +02:00
Merge pull request #235 from ahausladen/FixSubProcessCOMThreadModel
Fixes #234 "Invalid COM thread model change" with Debug-DLLs
This commit is contained in:
@ -51,11 +51,11 @@ interface
|
|||||||
uses
|
uses
|
||||||
{$IFDEF DELPHI16_UP}
|
{$IFDEF DELPHI16_UP}
|
||||||
{$IFDEF MSWINDOWS}
|
{$IFDEF MSWINDOWS}
|
||||||
WinApi.Windows, {$IFNDEF FMX}Vcl.Forms,{$ENDIF}
|
WinApi.Windows, {$IFNDEF FMX}Vcl.Forms, WinApi.ActiveX,{$ENDIF}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
System.Classes, System.UITypes,
|
System.Classes, System.UITypes,
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
{$IFDEF MSWINDOWS}Windows, Forms,{$ENDIF} Classes, {$IFDEF FPC}dynlibs,{$ENDIF}
|
{$IFDEF MSWINDOWS}Windows, Forms, ActiveX,{$ENDIF} Classes, {$IFDEF FPC}dynlibs,{$ENDIF}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
uCEFTypes, uCEFInterfaces, uCEFBaseRefCounted, uCEFSchemeRegistrar;
|
uCEFTypes, uCEFInterfaces, uCEFBaseRefCounted, uCEFSchemeRegistrar;
|
||||||
|
|
||||||
@ -137,6 +137,7 @@ type
|
|||||||
FDisableWebSecurity : boolean;
|
FDisableWebSecurity : boolean;
|
||||||
FDisablePDFExtension : boolean;
|
FDisablePDFExtension : boolean;
|
||||||
FLogProcessInfo : boolean;
|
FLogProcessInfo : boolean;
|
||||||
|
FDestroyApplicationObject : boolean;
|
||||||
FDestroyAppWindows : boolean;
|
FDestroyAppWindows : boolean;
|
||||||
FEnableFeatures : string;
|
FEnableFeatures : string;
|
||||||
FDisableFeatures : string;
|
FDisableFeatures : string;
|
||||||
@ -450,6 +451,7 @@ type
|
|||||||
property ChromeElfPath : string read GetChromeElfPath;
|
property ChromeElfPath : string read GetChromeElfPath;
|
||||||
property LibLoaded : boolean read FLibLoaded;
|
property LibLoaded : boolean read FLibLoaded;
|
||||||
property LogProcessInfo : boolean read FLogProcessInfo write FLogProcessInfo;
|
property LogProcessInfo : boolean read FLogProcessInfo write FLogProcessInfo;
|
||||||
|
property DestroyApplicationObject : boolean read FDestroyApplicationObject write FDestroyApplicationObject;
|
||||||
property DestroyAppWindows : boolean read FDestroyAppWindows write FDestroyAppWindows;
|
property DestroyAppWindows : boolean read FDestroyAppWindows write FDestroyAppWindows;
|
||||||
property ReRaiseExceptions : boolean read FReRaiseExceptions write FReRaiseExceptions;
|
property ReRaiseExceptions : boolean read FReRaiseExceptions write FReRaiseExceptions;
|
||||||
property DeviceScaleFactor : single read FDeviceScaleFactor;
|
property DeviceScaleFactor : single read FDeviceScaleFactor;
|
||||||
@ -553,7 +555,7 @@ implementation
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
{$IFDEF DELPHI16_UP}
|
{$IFDEF DELPHI16_UP}
|
||||||
System.Math, System.IOUtils, System.SysUtils, {$IFDEF MSWINDOWS}WinApi.TlHelp32, PSAPI,{$ENDIF}
|
System.Math, System.IOUtils, System.SysUtils, {$IFDEF MSWINDOWS}WinApi.TlHelp32, WinApi.PSAPI,{$ENDIF}
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
Math, {$IFDEF DELPHI14_UP}IOUtils,{$ENDIF} SysUtils,
|
Math, {$IFDEF DELPHI14_UP}IOUtils,{$ENDIF} SysUtils,
|
||||||
{$IFDEF FPC}
|
{$IFDEF FPC}
|
||||||
@ -629,6 +631,7 @@ begin
|
|||||||
FDisableWebSecurity := False;
|
FDisableWebSecurity := False;
|
||||||
FDisablePDFExtension := False;
|
FDisablePDFExtension := False;
|
||||||
FLogProcessInfo := False;
|
FLogProcessInfo := False;
|
||||||
|
FDestroyApplicationObject := False;
|
||||||
FDestroyAppWindows := True;
|
FDestroyAppWindows := True;
|
||||||
FReRaiseExceptions := False;
|
FReRaiseExceptions := False;
|
||||||
FLibLoaded := False;
|
FLibLoaded := False;
|
||||||
@ -788,6 +791,11 @@ end;
|
|||||||
function TCefApplication.SingleExeProcessing : boolean;
|
function TCefApplication.SingleExeProcessing : boolean;
|
||||||
var
|
var
|
||||||
TempApp : ICefApp;
|
TempApp : ICefApp;
|
||||||
|
{$IFNDEF FPC}
|
||||||
|
{$IFNDEF FMX}
|
||||||
|
AppDestroy: procedure(Obj: TApplication; ReleaseMemoryFlag: Byte);
|
||||||
|
{$ENDIF}
|
||||||
|
{$ENDIF}
|
||||||
begin
|
begin
|
||||||
Result := False;
|
Result := False;
|
||||||
TempApp := nil;
|
TempApp := nil;
|
||||||
@ -797,7 +805,27 @@ begin
|
|||||||
begin
|
begin
|
||||||
{$IFNDEF FPC}
|
{$IFNDEF FPC}
|
||||||
{$IFNDEF FMX}
|
{$IFNDEF FMX}
|
||||||
if FDestroyAppWindows and (ProcessType <> ptBrowser) and (Application <> nil) then
|
if (ProcessType <> ptBrowser) and (Application <> nil) then
|
||||||
|
begin
|
||||||
|
if FDestroyApplicationObject then
|
||||||
|
begin
|
||||||
|
// Call the destructor in "inherited Destroy" mode. This makes it possible to undo
|
||||||
|
// all the code that TApplication.Create did without actually releasing the Application
|
||||||
|
// object so that TControl.Destroy and DoneApplication dont't crash.
|
||||||
|
//
|
||||||
|
// Undoing also includes destroying the "AppWindows" and calling OleUninitialize what
|
||||||
|
// allows CEF to initialize the COM thread model the way it is required in the
|
||||||
|
// sub-processes (debug assertion).
|
||||||
|
AppDestroy := @TApplication.Destroy;
|
||||||
|
AppDestroy(Application, 0);
|
||||||
|
// Set all sub-objects to nil (we destroyed them already). This prevents the second
|
||||||
|
// TApplication.Destroy call in DoneApplication from trying to release already released
|
||||||
|
// objects.
|
||||||
|
TApplication.InitInstance(Application);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
if FDestroyAppWindows then
|
||||||
begin
|
begin
|
||||||
// This is the fix for the issue #139
|
// This is the fix for the issue #139
|
||||||
// https://github.com/salvadordf/CEF4Delphi/issues/139
|
// https://github.com/salvadordf/CEF4Delphi/issues/139
|
||||||
@ -811,6 +839,14 @@ begin
|
|||||||
if (Application.PopupControlWnd <> 0) then DeallocateHWnd(Application.PopupControlWnd);
|
if (Application.PopupControlWnd <> 0) then DeallocateHWnd(Application.PopupControlWnd);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
if not IsLibrary then
|
||||||
|
begin
|
||||||
|
// Undo the OleInitialize from TApplication.Create. The sub-processes want a different
|
||||||
|
// COM thread model and fail with an assertion if the Debug-DLLs are used.
|
||||||
|
OleUninitialize;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user