salvadordf / CEF4Delphi

CEF4Delphi is an open source project to embed Chromium-based browsers in applications made with Delphi or Lazarus/FPC for Windows, Linux and MacOS.
https://www.briskbard.com/forum/
Other
1.21k stars 369 forks source link

Error when loading large images #437

Closed hcort closed 2 years ago

hcort commented 2 years ago

I've found that trying to open large images results in a blank browser.

This is some image I'm using for test purposes: https://i.imgur.com/izXp9qR.jpg

This is a small sample code to reproduce the error:

procedure TForm1.FormShow(Sender: TObject);
begin
  Chromium.CreateBrowser(CEFWindowParent, '');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Chromium.LoadURL('https://i.imgur.com/izXp9qR.jpg');
end;

The image renders ok in chromium.

salvadordf commented 2 years ago

Add this to the DPR file of your application : {$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE} https://github.com/salvadordf/CEF4Delphi/blob/44e61874dd81b5059ecfacd8c69c21ee10000c65/demos/Delphi_VCL/SimpleBrowser/SimpleBrowser.dpr#L53

CEF needs to set the LARGEADDRESSAWARE flag which allows 32-bit processes to use up to 3GB of RAM. If you don't add this flag the rederer process will crash when you try to load large images.

IMAGE_FILE_LARGE_ADDRESS_AWARE is defined in Winapi.Windows and it has a value of $20. Some demos just use this line to avoid adding Winapi.Windows to the uses clause : {$SetPEFlags $20} https://github.com/salvadordf/CEF4Delphi/blob/44e61874dd81b5059ecfacd8c69c21ee10000c65/demos/Delphi_VCL/SubProcess/SimpleBrowser_sp.dpr#L47