Recent

Author Topic: Why WebKitGTK creates on Linux Exception, fpc-linux error?  (Read 5038 times)

SunyD

  • Guest
Why WebKitGTK creates on Linux Exception, fpc-linux error?
« on: March 28, 2011, 11:57:34 pm »
I created basic code for WebKitGtk-Widget.
On Windows the programm running without Errors.
But if I compile and run, the programm crashes on some websites.

Has the fpc-compiler errors/bugs on linux?
Because i compiled some c-examples with gcc they runs without errors on linux.

Here is the example code:
Code: [Select]
// webkitgtk1.pas - webkitgtk example
// compile: fpc webkitgtk1.pas
// for smaller exe-size: fpc -CX -XX -O2 webkitgtk1.pas
// on linux (ubuntu 10.10) it crashes with exception sigfpe
// on windows it's working perfect!
// same code as c-example working,
// Has fpc for linux (compiled with 2.4.3 and 2.4.2) error/bug?

// some codes are taken from here:
// http://freepascal-bits.blogspot.com/2009/10/webkit-experimenting.html

program webkitgtk1;
{$mode objfpc}{$H+}

//it dont starts with use math; on linux!
{$IFDEF WINDOWS} {$DEFINE USE_MATH} {$ENDIF}

//UseCThreads don't stop exception:
//{.$DEFINE UseCThreads}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
 
  {$IFDEF USE_MATH} math,{$ENDIF}
 
  Glib2, Gtk2;

const
 {$IFDEF UNIX}
  WEBKIT_LIB = 'webkitgtk-1.0'; //<--ubuntu 10.10  old: 'webkit-1.0';
 {$ELSE}
  WEBKIT_LIB = 'libwebkit-1.0-2.dll';
 {$ENDIF}

{$IFDEF WINDOWS}
  {$DEFINE WKGTK}
{$ENDIF}

type
  WebKitWebView = record            //look for definition: http://webkitgtk.org/reference/webkitgtk-webkitwebview.html#WebKitWebView
    parent_instance: TGtkContainer;   
    {$IFDEF WKGTK} priv: pointer; {$ENDIF WKGTK}  //this definiton isn't exists in webkitgtk-1.0          
  end;
  PWebKitWebView = ^WebKitWebView;
 
function web_view_new(): PGtkWidget; cdecl; external WEBKIT_LIB name 'webkit_web_view_new';
procedure web_view_open(web_view: PWebKitWebView; uri: Pgchar); cdecl; external WEBKIT_LIB name 'webkit_web_view_open';

                                 //:GtkObject
procedure OnMainForm1Destroy(widget: pGtkWidget; data: gpointer); cdecl;
begin
  gtk_main_quit;
end;

var MainWin1 : PGtkWidget;
    Box1 : PGtkWidget;
    Wkb1, WkScr1 : PGtkWidget;
   
begin
  // useless it doesn't stop exceptions, with this you can start any site!
  {$IFDEF USE_MATH}
  math.SetExceptionMask([exInvalidOp, exPrecision]); // strange magic, removes webkit's SIGFPE
  {$ENDIF}
 
  gtk_init (@argc, @argv);
 
  MainWin1:= gtk_window_new(GTK_WINDOW_TOPLEVEL);
   g_signal_connect(G_OBJECT(MainWin1), 'destroy', G_CALLBACK(@OnMainForm1Destroy), nil);
   gtk_widget_set_name(MainWin1, 'webkitgtkpas');
   gtk_window_set_default_size(PGtkWindow(MainWin1), 400,200); 
 
  Box1 := gtk_vbox_new(FALSE, 0);
  gtk_container_add(GTK_CONTAINER(MainWin1), Box1);
 
  WkScr1 := gtk_scrolled_window_new(nil, nil);
   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(WkScr1), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
 
  //for test-porpose only: Wkb1 := gtk_text_view_new;
   
  Wkb1 := web_view_new;
   gtk_container_add(GTK_CONTAINER(WkScr1), GTK_WIDGET(Wkb1)); 
   
 
  gtk_box_pack_start (GTK_BOX(Box1), WkScr1, TRUE, TRUE, 0);
 
  gtk_widget_show(WkScr1);
  gtk_widget_show(Wkb1);
  gtk_widget_show(Box1);
  gtk_widget_show(MainWin1); //  gtk_widget_show_all(MainWin1);

  web_view_open(PWebKitWebView(Wkb1), 'http://www.freepascal.org');
   
  gtk_main ();
end.


I compiled on Ubuntu 11.04 and 10.10 with fpc 2.4.2 and 2.4.3 (all i386-32Bit)