gtkwidget + sprintf = bug ??



Hello all

I have a problem when combining sprintf and 6 declarations of widget
pointers. Sounds strange but I can explain. Look at the function end of
this mail: 

This function works, but in order to make it works better (having the
entries already precompleted), I need to suppress the comments around the
2 sprintf. If I do this the function crashes the program (off course whe
executing theirst sprintf) fthe program with a nice message: ** ERROR **:
sigsegv caught

I have traced down the problem and realized that if I want to use sprintf,
I have to declare at max 5 pointers to gtkwidget (for this function I need
6:( ) 

Is it a bug of gtk? Or is it me that do something wrong? 

I use : 
	gcc-2.7.2.3-11
	glibc-2.0.7-13
	gtk+-1.0.2-1

Hope someone will be abble to help. 

Bye
-------------------------------------------------------
 Ryo | Pierre Loubigniac
 P.Loubigniac@bton.ac.uk
 http://ituser.it.bton.ac.uk/student/pl55/public_html/
-------------------------------------------------------


void 
knotvector_set(void)  
{
 /* prepare the variables */
 static GtkWidget *window = NULL; 
 GtkWidget *box1, *box2; 
 GtkWidget *entry, *entry2; 
 GtkWidget *button; 
 char *str;
 int i; 

 /* create the dialog window */
 window = gtk_window_new (GTK_WINDOW_TOPLEVEL); 
 gtk_signal_connect_object(GTK_OBJECT(window), "destroy",
                           GTK_SIGNAL_FUNC(gtk_widget_destroy),
                           GTK_OBJECT(window)); 

 gtk_window_set_title (GTK_WINDOW (window), "edit knotvector"); 
 gtk_container_border_width (GTK_CONTAINER (window), 0); 

 /* a box to put the dialog boxes */
 box1 = gtk_vbox_new (FALSE, 0); 
 gtk_container_add (GTK_CONTAINER (window), box1); 
 gtk_widget_show (box1); 

 /* create dialog box for each knot */ 
for (i = 0; i < attributes.index + 4; i++) 
        {
         box2 = gtk_hbox_new (FALSE, 0); 
         gtk_container_add (GTK_CONTAINER (box1), box2); 
         gtk_widget_show (box2); 

        /* A text box to get knot number */
         entry = gtk_entry_new ();
/* 
	 sprintf(str,"%d",i); 
         gtk_entry_set_text (GTK_ENTRY (entry),str); 
         gtk_entry_set_editable (GTK_ENTRY (entry), FALSE);  
*/
	 gtk_box_pack_start (GTK_BOX (box2), entry, TRUE, TRUE, 0); 
         gtk_widget_show (entry); 

         /* A text box to set the knot value */
         entry2 = gtk_entry_new ();  
/*
	 sprintf(str,"%d",knotvector[i]); 
         gtk_entry_set_text (GTK_ENTRY (entry2),str);  
*/
	 gtk_entry_set_editable (GTK_ENTRY (entry2), TRUE); 

         gtk_box_pack_start (GTK_BOX (box2), entry2, TRUE, TRUE, 0); 
         gtk_widget_show (entry2); 

         /* an update button */

         button = gtk_button_new_with_label ("update"); 
         gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                                   GTK_SIGNAL_FUNC (get_knot),
                                   GTK_OBJECT (entry)); 
         gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                                   GTK_SIGNAL_FUNC (update_knotvector),
                                   GTK_OBJECT (entry2)); 

         gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); 
         gtk_widget_show(button); 
        }

 /* a uniform knot vector to set ... then kill the window */
 button = gtk_button_new_with_label ("uniform knot vector"); 
 gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                           GTK_SIGNAL_FUNC (set_uniform_knotvector),
                           NULL); 
 gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                           GTK_SIGNAL_FUNC (gtk_widget_destroy),
                           GTK_OBJECT (window)); 
 gtk_box_pack_start (GTK_BOX (box1), button, TRUE, TRUE, 0); 
 gtk_widget_show(button); 

 /* an close button to kill the window */
 button = gtk_button_new_with_label ("close"); 
 gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                           GTK_SIGNAL_FUNC (gtk_widget_destroy),
                           GTK_OBJECT (window)); 
 gtk_box_pack_start (GTK_BOX (box1), button, TRUE, TRUE, 0); 
 gtk_widget_show(button); 

 /* show it all */
 gtk_widget_show (window);  
}








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