mrliyouliang / delphichromiumembedded

Automatically exported from code.google.com/p/delphichromiumembedded
0 stars 0 forks source link

Access Violation / possible race condition #19

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. New Application
2. Drop TChromium
3. FormCreate Event:
  Chromium1.Browser.MainFrame.LoadUrl('file:///./test.html');
5. Make sure you have a "test.html" file in the project directory
6. Run app

What is the expected output? What do you see instead?
I expect the program to run and TChromium to display the HTML file, instead I 
get an Access Violation exception.

What version of the product are you using? On what operating system?
delphichromiumembedded SVN trunk rev 27
cef_binary_r181_VS2005-VS2008
Delphi 7
Windows XP SP3

Please provide any additional information below.
It seems to be a race condition.  If I do this it works:
7. Drop TButton on form
8. Move code from FormCreate to a Button1Click Event:
  Chromium1.Browser.MainFrame.LoadUrl('file:///./test.html');
9. After launching, click the button.

Or if I LoadURL in the FormShow event with a delay it works:

  procedure TForm1.FormShow(Sender: TObject);
  begin
    Sleep(100);
    Application.ProcessMessages;
    Chromium1.Browser.MainFrame.LoadUrl('file:///./test.html');
  end;

If I remove the delay, I get intermittent AV exceptions.

Original issue reported on code.google.com by adar...@gmail.com on 5 Feb 2011 at 11:28

GoogleCodeExporter commented 8 years ago
One thing that I can test pretty consistently is that it takes some time for 
the Browser field to become valid:

  while Chromium1.Browser = nil do begin
    Sleep(100);
    Application.ProcessMessages;
  end;

Besides that, there must be another internal race, because the MainForm field 
sometimes never becomes valid:

  while Chromium1.Browser.MainFrame = nil do begin
    Sleep(100);
    Application.ProcessMessages;
  end;
  //sometimes we never get here, but get stuck in the loop above
  Chromium1.Browser.MainFrame.LoadUrl('file:///./test.html');

It appears to me that the slower it is to launch the program and load its 
libraries, the more likely the problem is to exhibit itself.

Original comment by adar...@gmail.com on 6 Feb 2011 at 12:43

GoogleCodeExporter commented 8 years ago
The browser is multithreaded, you have to wait the onaftercreated event to have 
a valid browser instance.
The first time use the DefaultUrl property.

Original comment by hgourv...@gmail.com on 8 Feb 2011 at 8:41

GoogleCodeExporter commented 8 years ago
Thanks :-) Works now.  If you create an initial wiki page, I would be happy to 
add some documentation about this.

Original comment by adar...@gmail.com on 8 Feb 2011 at 7:05