Re: seg fault in mahjongg - Fix & additional question



The attached patch fixes the reported problem (could someone please 
commit this to CVS ?), but there is a slight issue.

The fix essentially replaces the line :
    gtk_timeout_remove (timer);
in the timeout handler with :
    return 0;
both of which, according to the GTK tutorial, stop the timer. Now it 
doesn't entirely surprise me that deleting the timer before exiting that 
timer's handler routine causes the main loop to go ape-shit, but is it 
meant to be such a bad thing ?

This should probably be sent to the GTK list, but I'm trying to restrict 
myself to one high-volume mailing list at a time, sorry.

For those of you wondering how a one-line change gets to be a 3k patch 
file, the patch also fixes the next bug with hints and gets rid of a few 
compiler warnings.

 - Callum
? diff.1
Index: mahjongg.c
===================================================================
RCS file: /cvs/gnome/gnome-games/mahjongg/mahjongg.c,v
retrieving revision 1.44
diff -u -r1.44 mahjongg.c
--- mahjongg.c	1998/12/30 19:47:44	1.44
+++ mahjongg.c	1999/01/07 06:15:32
@@ -27,6 +27,8 @@
 
 #include "button-images.h"
 
+#define HINT_BLINK_NUM 5
+
 typeinfo type_info [MAX_TILES+70] = {
   	{ 0, 0, {0, 0} },
 	{ 0, 0, {0, 0} },
@@ -336,7 +338,7 @@
 
 gint hint_tiles[2];
 guint timer;
-guint timeout_counter = 0;
+guint timeout_counter = HINT_BLINK_NUM + 1;
 
 void clear_undo_queue ();
 void you_won (void);
@@ -561,7 +563,7 @@
 tile_event (GnomeCanvasItem *item, GdkEvent *event, tile *tile_inf)
 {
   gchar tmpchar[4];
-  
+ 
   switch(event->type) {
 	  case GDK_BUTTON_PRESS :
 	    if((event->button.button == 1) && tile_free(tile_inf->number)) {
@@ -938,23 +940,21 @@
 }
 
 gint hint_timeout (gpointer data)
-{
-  if (timeout_counter <= 4) {
-    if (tiles[hint_tiles[0]].selected == 17) {
-      tiles[hint_tiles[0]].selected = 0;
-      tiles[hint_tiles[1]].selected = 0;
-    }
-    else {
-      tiles[hint_tiles[0]].selected = 17;
-      tiles[hint_tiles[1]].selected = 17;
-    }
-    change_tile_image(&tiles[hint_tiles[0]]);
-    change_tile_image(&tiles[hint_tiles[1]]);
-  }
-  else {
-    gtk_timeout_remove (timer);
-  }
+{	
   timeout_counter ++;
+
+  if (timeout_counter > HINT_BLINK_NUM)
+	  return 0;
+	  
+  if (tiles[hint_tiles[0]].selected == 17) {
+    tiles[hint_tiles[0]].selected = 0;
+    tiles[hint_tiles[1]].selected = 0;
+  } else {
+    tiles[hint_tiles[0]].selected = 17;
+    tiles[hint_tiles[1]].selected = 17;
+  }
+  change_tile_image(&tiles[hint_tiles[0]]);
+  change_tile_image(&tiles[hint_tiles[1]]);
   return 1;
 }
 
@@ -965,6 +965,11 @@
   if (hint_dialog)
     return;
 
+  /* This prevents the flashing speeding up if the hint button is
+   * pressed multiple times. */
+  if (timeout_counter<=HINT_BLINK_NUM) 
+    return;
+
   /* Snarfed from check free
    * Tile Free is now _so_ much quicker, it is more elegant to do a
    * British Library search, and safer. */
@@ -1123,7 +1128,7 @@
 static void
 input_callback (GtkWidget *widget, gpointer data)
 {
-	srand (atoi (GTK_ENTRY (data)->text));
+	srand (atoi ((char *)(GTK_ENTRY (data)->text)));
 	new_game ();
 }
 
@@ -1189,12 +1194,12 @@
     if((GTK_CHECK_MENU_ITEM(optionsmenu[0].widget))->active)
     {
         gnome_config_set_bool("gmahjongg/toolbar/show", TRUE);
-        gtk_widget_show(gdi);
+        gtk_widget_show(GTK_WIDGET(gdi));
     }
     else
     {
         gnome_config_set_bool("gmahjongg/toolbar/show", FALSE);
-        gtk_widget_hide(gdi);
+        gtk_widget_hide(GTK_WIDGET(gdi));
     }
 }
 
@@ -1407,7 +1412,7 @@
         if(gnome_config_get_bool("/gmahjongg/toolbar/show=TRUE"))
             gtk_check_menu_item_set_state(GTK_CHECK_MENU_ITEM(optionsmenu[0].widget), TRUE);
         else
-	    gtk_widget_hide(gdi);
+	    gtk_widget_hide(GTK_WIDGET(gdi));
 
         tiles_label = gtk_label_new(_("Tiles"));
         gtk_widget_show(tiles_label);


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