Mahjongg crash.




On Mon, 8 Jun 1998, Marc Ewing wrote:
> We're looking into this.  It's quite a mystery though, and looks like
> a loader bug.

	Right, it looked odd.

> The RPMs got loose prematurely.  We're working on real ones now
> and we'll make an announcement when they are available.

	Great; whilst I was fiddling with Mahjongg trying to get a
solvable game generated each time :-), I noticed that there was a missing
malloc / duff definition of tmpchar that made it crash every time a tile
is turned.

	My fix for this, implementing undo functionality, is attached. 

	Regards,

		Michael Meeks.

-- 
 michael@imaginator.com  <><, Pseudo Engineer, itinerant idiot
*** mahjongg/mahjongg.c	Wed Jun  3 02:07:33 1998
--- oldmahjongg/mahjongg.c	Mon Jun  8 18:28:37 1998
***************
*** 252,271 ****
--- 252,273 ----
  	int layer;
  	int x;
  	int y;
  	int visible;
  	int selected;
+       int sequence;
  };
  
  GtkWidget *window, *pref_dialog;
  GtkWidget *mbox;
  GtkWidget *draw_area;
  GtkWidget *tiles_label;
  GdkPixmap *tiles_pix, *mask;
  GdkGC *my_gc;
  tile tiles[MAX_TILES];
  int selected_tile, visible_tiles;
+ int sequence_number;
  
  static GdkImlibImage *tiles_image;
  static gchar *tileset;
  
  static struct {
***************
*** 275,284 ****
--- 277,287 ----
  
  void load_tiles (char *fname);
  void quit_game_callback (GtkWidget *widget, gpointer data);
  void new_game_callback (GtkWidget *widget, gpointer data);
  void restart_game_callback (GtkWidget *widget, gpointer data);
+ void undo_tile_callback (GtkWidget *widget, gpointer data);
  void select_game_callback (GtkWidget *widget, gpointer date);
  void new_game (void);
  void properties_callback (GtkWidget *widget, gpointer data);
  void redraw_area (int x1, int y1, int x2, int y2, int mlayer);
  void about_callback (GtkWidget *widget, gpointer data);
***************
*** 299,309 ****
           {GNOME_APP_UI_SEPARATOR},
  
           {GNOME_APP_UI_ITEM, N_("Hint"), NULL, NULL, NULL, NULL,
           GNOME_APP_PIXMAP_NONE, NULL, 0, 0, NULL},
  
!          {GNOME_APP_UI_ITEM, N_("Undo"), NULL, NULL, NULL, NULL,
           GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_UNDO, 0, 0, NULL},
  
           {GNOME_APP_UI_SEPARATOR},
  	
           {GNOME_APP_UI_ITEM, N_("Exit"), NULL, quit_game_callback, NULL, NULL,
--- 302,312 ----
           {GNOME_APP_UI_SEPARATOR},
  
           {GNOME_APP_UI_ITEM, N_("Hint"), NULL, NULL, NULL, NULL,
           GNOME_APP_PIXMAP_NONE, NULL, 0, 0, NULL},
  
!          {GNOME_APP_UI_ITEM, N_("Undo"), NULL, undo_tile_callback, NULL, NULL,
           GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_UNDO, 0, 0, NULL},
  
           {GNOME_APP_UI_SEPARATOR},
  	
           {GNOME_APP_UI_ITEM, N_("Exit"), NULL, quit_game_callback, NULL, NULL,
***************
*** 365,375 ****
           GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_PIXMAP_REFRESH, 0, 0, NULL},
  
           {GNOME_APP_UI_ITEM, N_("Hint"), NULL, NULL, NULL, NULL,
           GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_PIXMAP_HELP, 0, 0, NULL},
  
!          {GNOME_APP_UI_ITEM, N_("Undo"), NULL, NULL, NULL, NULL,
           GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_PIXMAP_UNDO, 0, 0, NULL},
  
           {GNOME_APP_UI_TOGGLEITEM, N_("Sound"), NULL, NULL, NULL, NULL,
           GNOME_APP_PIXMAP_DATA, mini_sound_xpm, 0, 0, NULL},
  
--- 368,378 ----
           GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_PIXMAP_REFRESH, 0, 0, NULL},
  
           {GNOME_APP_UI_ITEM, N_("Hint"), NULL, NULL, NULL, NULL,
           GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_PIXMAP_HELP, 0, 0, NULL},
  
!          {GNOME_APP_UI_ITEM, N_("Undo"), NULL, undo_tile_callback, NULL, NULL,
           GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_PIXMAP_UNDO, 0, 0, NULL},
  
           {GNOME_APP_UI_TOGGLEITEM, N_("Sound"), NULL, NULL, NULL, NULL,
           GNOME_APP_PIXMAP_DATA, mini_sound_xpm, 0, 0, NULL},
  
***************
*** 740,749 ****
--- 743,774 ----
          tiles[i].selected = 0;
      }
      gtk_widget_draw (draw_area, NULL);
  }
  
+ void  undo_tile_callback (GtkWidget *widget, gpointer data)
+ {
+     int i;
+     gchar tmpchar[4] ;
+     
+     //    printf ("Undo\n") ;
+     if (sequence_number>1)
+       sequence_number-- ;
+     for (i=0; i<144; i++)
+       if (tiles[i].sequence == sequence_number)
+ 	{
+ 	  tiles[i].sequence = 0 ;
+ 	  tiles[i].selected = 0 ;
+ 	  tiles[i].visible = 1 ;
+ 	  visible_tiles++ ;
+ 	}
+ 
+     sprintf(tmpchar,"%d",visible_tiles) ;
+     gtk_label_set(GTK_LABEL(tiles_label), tmpchar);
+     gtk_widget_draw (draw_area, NULL);
+ }
+ 
  static void
  input_callback (GtkWidget *widget, gpointer data)
  {
  	srand (atoi (GTK_ENTRY (data)->text));
  	new_game ();
***************
*** 821,830 ****
--- 846,856 ----
  
  void new_game (void)
  {
  	int i, f, n;
  	
+ 	sequence_number = 1 ;
  	visible_tiles = 144;
  	for (f = 0; f < 144; f++) {
  		tiles[f].visible = 0;
  	}
  	selected_tile = MAX_TILES + 1;
***************
*** 840,849 ****
--- 866,876 ----
  			tiles[f].x = default_pos[f].x * (HALF_WIDTH-0) + 30 + (5 * default_pos[f].layer);
  			tiles[f].y = default_pos[f].y * (HALF_HEIGHT-0) + 25 - (4 * default_pos[f].layer);
  			tiles[f].layer = default_pos[f].layer;
  			tiles[f].type = default_types[i].type; 
  			tiles[f].image = default_types[i].image; 
+ 			tiles[f].sequence = 0 ;
  		}
  	}
  	
  	gtk_widget_draw (draw_area, NULL);
  }
***************
*** 926,936 ****
  }
  
  void button_pressed (int x, int y)
  {
  	int i;
!         gchar *tmpchar;
          
  	i = find_tile (x, y);
  	if (i < MAX_TILES) {
  		if (tile_free (i)) {
  			if (selected_tile < MAX_TILES) {
--- 953,963 ----
  }
  
  void button_pressed (int x, int y)
  {
  	int i;
!         gchar tmpchar[4];
          
  	i = find_tile (x, y);
  	if (i < MAX_TILES) {
  		if (tile_free (i)) {
  			if (selected_tile < MAX_TILES) {
***************
*** 940,949 ****
--- 967,978 ----
  					tiles[selected_tile].visible = 0;
  					tile_gone (i, x, y);
  					tile_gone (selected_tile,
  						   tiles[selected_tile].x + 1,
  						   tiles[selected_tile].y + 1);
+ 					tiles[i].sequence = sequence_number ;
+ 					tiles[selected_tile].sequence = sequence_number++ ;
  					selected_tile = MAX_TILES + 1;
                                          visible_tiles -= 2;
                                          sprintf(tmpchar,"%d",visible_tiles);
                                          gtk_label_set(GTK_LABEL(tiles_label), tmpchar);
  					check_free();


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