Problem: Multithread Application and gtk_widget_show with gtk-2.0




Hi all,

I have a application that was build using the gtk-1.2 redhat 9.0. The application has two threads. The main thread is the display thread, while the second one updates the display sometimes.
When the second thread updated the display , The following error occured:
---------------------------------
Thread2:
    update_alarm_report_window() <- function called
    Xlib: unexpected async reply (sequence 0x5c07)!
------------------------------------------------

I got over the problem by compiling with following options

gcc -o out test.c `pkg-config --cflags --libs libgnome-2.0 libgnomeui-2.0 gthread`

    Thank to Frank W. Miller for listing out the compilation and link steps of the g_threads_init so clearly.  This is exactly what works.

After successful compilation, I could never bring up the application: In fact the main thread dumped with the following error at the very begning while showing the very first screen

----------------------------------------
Thread1:


DH: create_login_window called
DH: DEBUG1
GLib-GObject-CRITICAL **: gtype.c:1875: initialization assertion failed, use g_type_init() prior to this function

GLib-GObject-CRITICAL **: file gobject.c: line 615 (g_object_new): assertion `G_TYPE_IS_OBJECT (object_type)' failed
------------------------------------------

So I added the following call

  g_type_init();                                 



Then I got the following Error:

------------------------------------------
DH: create_login_window called
DEBUG1
Gdk-CRITICAL **: file gdkvisual-x11.c: line 533 (gdk_screen_list_visuals): assertion `GDK_IS_SCREEN (screen)' failed

----------------------------------------

I explicitly checked the return value of the gdk_screen_list_visuals() function. It is NULL.

Please HELP.

Regards

Rita


The code is as follows:

int
main(int argc, char* argv[])
{
  g_print("\nDH: initialize_display called");

  g_type_init();                                 
  g_thread_init(NULL);
  gdk_init(&argc, &argv);
  gdk_threads_init();
  gdk_threads_enter (); 
  gtk_init (&argc, &argv);
 
  gnome_init ("nw_map", "0.1", argc, argv);
  gtk_rc_parse( "resource.rc" );
 
  // Create the login window
  create_login_window(NULL);  <<<<<<<<<<<-------------GUI Function Defined below

  gtk_main();
  gdk_threads_leave ();
}



void create_login_window (GtkWidget *prev_win)
{
  GtkWidget *login_window;
  GtkWidget *fixed1;
  GtkWidget *login_label;
  GtkWidget *login_entry;
  GtkWidget *password_label;
  GtkWidget *password_entry;
  GtkWidget *login_button;
  GtkWidget *login_cancel_button;
  GList    *gl;

  g_print("\n create_login_window called");
  if (prev_win != NULL)
    gtk_widget_destroy (prev_win);

  gl=NULL;

  login_window = gtk_window_new (GTK_WINDOW_DIALOG);
  gtk_object_set_data (GTK_OBJECT (login_window), "login_window", login_window);
  gtk_window_set_title (GTK_WINDOW (login_window), _("LOGIN"));

  gtk_window_set_position (GTK_WINDOW (login_window), GTK_WIN_POS_CENTER);
  gtk_window_set_modal (GTK_WINDOW (login_window), TRUE);
  gtk_window_set_default_size(GTK_WINDOW(login_window),360,250);

  fixed1 = gtk_fixed_new ();
  gtk_widget_ref (fixed1);
  gtk_object_set_data_full (GTK_OBJECT (login_window), "fixed1", fixed1,
                            (GtkDestroyNotify) gtk_widget_unref);

  gtk_widget_show (fixed1);
  gtk_container_add (GTK_CONTAINER (login_window), fixed1);

  login_label = gtk_label_new (_("Login"));
  gtk_widget_ref (login_label);
  gtk_object_set_data_full (GTK_OBJECT (login_window), "login_label", login_label,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (login_label);
  gtk_fixed_put (GTK_FIXED (fixed1), login_label, 56, 56);
  gtk_widget_set_uposition (login_label, 56, 56);
  gtk_widget_set_usize (login_label, 35, 16);

  login_entry = gtk_entry_new_with_max_length (30);
  gtk_widget_ref (login_entry);
  gtk_object_set_data_full (GTK_OBJECT (login_window), "login_entry", login_entry,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (login_entry);
  gtk_fixed_put (GTK_FIXED (fixed1), login_entry, 136, 56);
  gtk_widget_set_uposition (login_entry, 136, 56);
  gtk_widget_set_usize (login_entry, 158, 22);

  password_label = gtk_label_new (_("Password"));
  gtk_widget_ref (password_label);
  gtk_object_set_data_full (GTK_OBJECT (login_window), "password_label", password_label,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (password_label);
  gtk_fixed_put (GTK_FIXED (fixed1), password_label, 56, 120);
  gtk_widget_set_uposition (password_label, 56, 120);
  gtk_widget_set_usize (password_label, 55, 16);

  password_entry = gtk_entry_new_with_max_length (15);
  gtk_widget_ref (password_entry);
  gtk_object_set_data_full (GTK_OBJECT (login_window), "password_entry", password_entry,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (password_entry);
  gtk_fixed_put (GTK_FIXED (fixed1), password_entry, 136, 120);
  gtk_widget_set_uposition (password_entry, 136, 120);
  gtk_widget_set_usize (password_entry, 158, 22);
  gtk_entry_set_visibility (GTK_ENTRY (password_entry), FALSE);

  login_button = gtk_button_new_with_label (_("Login"));
  gtk_widget_ref (login_button);
  gtk_object_set_data_full (GTK_OBJECT (login_window), "login_button", login_button,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (login_button);
  gtk_fixed_put (GTK_FIXED (fixed1), login_button, 88, 208);
  gtk_widget_set_uposition (login_button, 88, 208);
  gtk_widget_set_usize (login_button, 80, 22);

  login_cancel_button = gnome_stock_button (GNOME_STOCK_BUTTON_CANCEL);
  gtk_widget_ref (login_cancel_button);
  gtk_object_set_data_full (GTK_OBJECT (login_window), "login_cancel_button", login_cancel_button,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (login_cancel_button);
  gtk_fixed_put (GTK_FIXED (fixed1), login_cancel_button, 200, 208);
  gtk_widget_set_uposition (login_cancel_button, 200, 208);
  gtk_widget_set_usize (login_cancel_button, 80, 22);

  gl=g_list_append(gl,login_entry);
  gl=g_list_append(gl,password_entry);
  gl=g_list_append(gl,login_window);
 
  gtk_signal_connect (GTK_OBJECT (login_button), "clicked",
                      GTK_SIGNAL_FUNC (on_login_ok_button_clicked),
                      gl);

  gtk_signal_connect (GTK_OBJECT (login_cancel_button), "clicked",
                      GTK_SIGNAL_FUNC (on_login_cancel_button_clicked),
                      gl );

 
  g_print("\nDH: DEBUG1");
  gtk_widget_show(login_window);    //<<<<<<<<<<<------------------FAILS HERE
  g_print("\nDH: DEBUG2");
}



The make uses the following :


gcc -Wall -DMIBTXTDIR=\"/usr/local/etc\" -DMIBDIR=\"/usr/local/share/gxsnmp/mibs\" -g -o .libs/nhms -rdynamic -rdynamic -DORBIT2=1 -pthread -I/usr/include/libgnome-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/orbit-2.0 -I/usr/include/libbonobo-2.0 -I/usr/include/gconf/2 -I/usr/include/gnome-vfs-2.0 -I/usr/lib/gnome-vfs-2.0/include -I/usr/include/linc-1.0 -I/usr/include/bonobo-activation-2.0 -I/usr/include/libgnomeui-2.0 -I/usr/include/libgnomecanvas-2.0 -I/usr/include/gtk-2.0 -I/usr/include/libart-2.0 -I/usr/include/libbonoboui-2.0 -I/usr/include/pango-1.0 -I/usr/include/freetype2 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/X11R6/include -I/usr/include/libxml2 -pthread -Wl,--export-dynamic -o .libs/nhms ../APP_NHMS/
display_handler.o data_handler.o
-lgnome -lgnomesupport -lesd -laudiofile -lm -L/usr/lib -L/usr/X11R6/lib -lgnorba -lORBitCosNaming -lORBit -lIIOP -lORBitutil -lnsl -lgnomeui -lart_lgpl -lgdk_imlib -lSM -lICE -ldl -lXi -lXext -lX11 -lm -ldl -lXi -lXext -lX11 -lm -ldl -ldl -lXi -lXext -lX11 -lgnome -lgnomesupport -lesd -laudiofile -lm /usr/lib/libgtk.so -ldl -lXi -lXext -lX11 -lm /usr/lib/libgdk.so -ldl -lXi -lXext -lX11 -lm /usr/lib/libgmodule.so -ldl /usr/lib/libglib.so -ldl -lXi -lXext -lX11 -lm -L/usr/lib/mysql -lmysqlclient -lpthread /usr/local/lib/libgxsnmp.so /usr/local/lib/libsmi.so /usr/local/lib/libgxsnmpapp.so /usr/local/lib/libgxsnmpdb.so -lgnomeui-2 -lSM -lICE -lbonoboui-2 /usr/lib/libxml2.so -lm -lz -lgnomecanvas-2 -lgnome-2 -lart_lgpl_2 -lpangoft2-1.0 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lpangoxft-1.0 -lpangox-1.0 -lpango-1.0 -lbonobo-2 -lgconf-2 -lgnomevfs-2 -lbonobo-activation -lORBit-2 -lm /usr/lib/liblinc.so -lgmodule-2.0 -ldl -lgobject-2.0 -lgthread-2.0 -lglib-2.0 -Wl,--rpath -Wl,/usr/local/lib
creating app



PLEASE HELP





 


                             
 





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]