heroes-discuss
[Top][All Lists]
Advanced

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

Re: [Heroes] Bug#169525: heroes-common: Fatal signal: Segmentation Fault


From: Alexandre Duret-Lutz
Subject: Re: [Heroes] Bug#169525: heroes-common: Fatal signal: Segmentation Fault (SDL Parachute Deployed)
Date: Wed, 20 Nov 2002 13:39:34 +0100
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/20.7 (i386-debian-linux-gnu)

>>> "Jean" == Jean Delvare <address@hidden> writes:

[...]

 Jean> #0  0x0804dad3 in initialize_deck_font () at fontdata.c:91
 Jean> #1  0x0806a6ce in draw_level (p=-1073743384) at render.c:548
 Jean> Cannot access memory at address 0x17
 Jean> (gdb)

This trace shows your stack is trashed :)

[...]

 Jean> I suspect the yellow spinning arrow (previously "Get this
 Jean> bonus" or something) around the Length+ bonus to be the
 Jean> cause (or part of it, at least).

You guessed right.  When these arrows revolve around a bonus,
they are also drawn on the neighboring tiles.  This caused
pixels to be written off the bottom of the rendering buffer.

I've installed a fix for this.

The following diff shows all the bug fixes I have against Heroes 0.21.

2002-11-20  Alexandre Duret-Lutz  <address@hidden>

        * src/media.video.h (ybuf, sbuf): Enlarge the height of the rendering
        buffer, otherwise rendering tutorial arrows can overflow and
        cause segfaults.
        Reported by Christoph Claus and Jean Delvare.

2002-08-22  Alexandre Duret-Lutz  <address@hidden>

        * src/menus.c (editor_entries): Add missing trailing { 0, 0 }.
        Reported by Nicolas Tisserand.  (Segfault on Debian/PPC)

2002-06-16  Alexandre Duret-Lutz  <address@hidden>

        * src/const.c (kbjoy, kbjoyold): Redefine as static bool[].
        (key_or_joy_reset): New function.
        * src/const.h (kbjoy, kbjoyold): Don't export.
        (key_or_joy_reset): New function.
        * src/menus.c (quit_yes_no): Don't wait for joystick buttons to go up.
        (pause_menu, quit_yes_no): Call key_or_joy_reset.
        * src/heroes.c (play_demo, play_game): Likewise.

2002-04-07  Alexandre Duret-Lutz  <address@hidden>

        * src/media/sdl/joystick.c (get_joystick_state): Make sure we
        never use SDL's Joystick API if it wasn't initialized.
        Reported by William Black.

2002-04-01  Alexandre Duret-Lutz  <address@hidden>

        * src/heroes.c (update_player): Typo in speed adjustment.

Index: src/const.c
===================================================================
RCS file: /cvsroot/heroes/heroes/src/const.c,v
retrieving revision 1.46
retrieving revision 1.46.2.2
diff -u -r1.46 -r1.46.2.2
--- src/const.c 18 Nov 2001 21:49:30 -0000      1.46
+++ src/const.c 16 Jun 2002 19:49:25 -0000      1.46.2.2
@@ -45,9 +45,6 @@
 /* int error; */
 char in_jokebox;
 
-char kbjoy[6] = { 0, 0, 0, 0, 0, 0 };
-char kbjoyold[6] = { 0, 0, 0, 0, 0, 0 };
-
 a_pixel *(render_buffer[2]);           /* xbuf * ybuf */
 
 a_pixel glenz[8][256];         /* glenz lines */
@@ -88,6 +85,15 @@
 
 char demo_ready = 0;
 
+/*
+ * An array of joystick buttons.  KBJOYOLD is the previous state.
+ * Button N has been pressed is KBJOY[N] && !KBJOYOLD[N].  Initially
+ * we assume that all buttons are down, so any button down before the
+ * first call to get_key_or_joy() is ignored.
+ */
+static bool kbjoy[6] = { true, true, true, true, true, true };
+static bool kbjoyold[6];
+
 char
 key_or_joy_ready (void)
 {
@@ -108,7 +114,7 @@
 
   if (key_ready ()) {
     reset_htimer (demo_trigger_htimer);
-    return (1);
+    return 1;
   }
   if ((joystick_detected & 1) && (opt.ctrl_one == 1 || opt.ctrl_two == 1)) {
     for (i = 0; i < 6; i++)
@@ -127,10 +133,10 @@
        || (kbjoy[4] && !kbjoyold[4])
        || (kbjoy[5] && !kbjoyold[5])) {
       reset_htimer (demo_trigger_htimer);
-      return (1);
+      return 1;
     }
   }
-  return (0);
+  return 0;
 }
 
 a_keycode
@@ -151,7 +157,17 @@
   if (kbjoy[5] && !kbjoyold[5])
     return (HK_Escape);
   printf ("get_key_or_joy(): no event.");
-  return (0);
+  return 0;
+}
+
+void
+key_or_joy_reset (void)
+{
+  /* Assume that all joystick buttons were down, so that
+     get_key_or_joy will not detect buttons that are already down.  */
+  int i;
+  for (i = 0; i < 6; i++)
+    kbjoy[i] = true;
 }
 
 void
@@ -165,5 +181,4 @@
       *dest = glenzligne[*dest];
     dest += xbuf - xt;
   }
-
 }
Index: src/const.h
===================================================================
RCS file: /cvsroot/heroes/heroes/src/const.h,v
retrieving revision 1.37
retrieving revision 1.37.2.1
diff -u -r1.37 -r1.37.2.1
--- src/const.h 8 Nov 2001 19:32:14 -0000       1.37
+++ src/const.h 16 Jun 2002 19:16:09 -0000      1.37.2.1
@@ -35,9 +35,8 @@
 
 char key_or_joy_ready (void);
 a_keycode get_key_or_joy (void);
+void key_or_joy_reset (void);
 
-extern char kbjoy[6];
-extern char kbjoyold[6];
 extern char in_jokebox;
 extern char in_menu;
 extern char in_demo;
Index: src/heroes.c
===================================================================
RCS file: /cvsroot/heroes/heroes/src/heroes.c,v
retrieving revision 1.154.2.1
retrieving revision 1.154.2.3
diff -u -r1.154.2.1 -r1.154.2.3
--- src/heroes.c        6 Feb 2002 21:52:48 -0000       1.154.2.1
+++ src/heroes.c        16 Jun 2002 19:16:09 -0000      1.154.2.3
@@ -1992,7 +1992,7 @@
       else
        player[c].vitp = player[c].vitt;
     else if (player[c].vitp > player[c].vitt) {
-      if (player[c].vitp + 512 > player[c].vitt)
+      if (player[c].vitp - 512 > player[c].vitt)
        player[c].vitp -= 512;
       else
        player[c].vitp = player[c].vitt;
@@ -2505,6 +2505,7 @@
 
   free_htimer (demo_htimer);
   uninit_keyboard_map ();
+  key_or_joy_reset ();
   unload_level ();
   nbr_tiles_cols = 15;
   in_menu = 1;
@@ -3001,6 +3002,7 @@
     dmsg (D_SECTION, "print end level info");
 
     uninit_keyboard_map ();
+    key_or_joy_reset ();
     l = 0;
     if (level_is_finished != 15)
       if (player[level_is_finished - 1].cpu == 2)
@@ -3283,12 +3285,12 @@
   if ((!notbyebye) || (level_is_finished == 15))
     l = 255;
   uninit_keyboard_map ();
+  key_or_joy_reset ();
   unload_level ();
   nbr_tiles_cols = 15;
   in_menu = 1;
-/* if (l!=0) cont=0; */
 
-  return (l);
+  return l;
 }
 
 int
Index: src/menus.c
===================================================================
RCS file: /cvsroot/heroes/heroes/src/menus.c,v
retrieving revision 1.108
retrieving revision 1.108.2.2
diff -u -r1.108 -r1.108.2.2
--- src/menus.c 14 Jan 2002 22:13:59 -0000      1.108
+++ src/menus.c 22 Aug 2002 11:45:51 -0000      1.108.2.2
@@ -219,7 +219,8 @@
   { N_("NEW LEVEL"),   editor_menu },
   /* TRANS: Load an existing level for edition.  */
   { N_("LOAD LEVEL"),  editor_selector },
-  { N_("GO BACK"),     0 }
+  { N_("GO BACK"),     0 },
+  { 0,                 0 }
 };
 
 a_menu *editor_menu_data;
@@ -2122,6 +2123,7 @@
   corner[0] = render_buffer[0];
 
   uninit_keyboard_map ();
+  key_or_joy_reset ();
   std_white_fadein (&dummy_background_img.palette);
   do {
     dummy_moving_background_render ();
@@ -2157,13 +2159,8 @@
 
   corner[0] = render_buffer[0];
 
-  if (opt.ctrl_one || opt.ctrl_two)
-    do {
-      get_joystick_state ();
-      flush_display (corner[0]);
-    } while (joystick_b[0] || joystick_b[1]);
-
   uninit_keyboard_map ();
+  key_or_joy_reset ();
   halve_volume ();
   event_sfx (85);
   std_white_fadein (&dummy_background_img.palette);
Index: src/media/video.h
===================================================================
RCS file: /cvsroot/heroes/heroes/src/media/video.h,v
retrieving revision 1.4
retrieving revision 1.4.6.1
diff -u -r1.4 -r1.4.6.1
--- src/media/video.h   21 Sep 2001 10:43:57 -0000      1.4
+++ src/media/video.h   20 Nov 2002 12:32:33 -0000      1.4.6.1
@@ -25,8 +25,8 @@
 /* the three macro below configure the rendering buffers used in the game */
 #define xbuf 512               /* large width to suppress any clipping need,
                                   power of two of easier multiplications */
-#define ybuf 300               /* height */
-#define sbuf (50*xbuf)         /* keep sbuf empty line on top of the buffers
+#define ybuf 320               /* height */
+#define sbuf (60*xbuf)         /* keep sbuf empty line on top of the buffers
                                   (to avoid clipping) */
 
 
Index: src/media/sdl/joystick.c
===================================================================
RCS file: /cvsroot/heroes/heroes/src/media/sdl/joystick.c,v
retrieving revision 1.2
retrieving revision 1.2.6.1
diff -u -r1.2 -r1.2.6.1
--- src/media/sdl/joystick.c    21 Sep 2001 10:43:57 -0000      1.2
+++ src/media/sdl/joystick.c    7 Apr 2002 18:55:59 -0000       1.2.6.1
@@ -63,6 +63,13 @@
 
 void get_joystick_state (void)
 {
+  /* Make sure we never use SDL's Joystick API if it wasn't
+     initialized (this happens when the game is run with -J): crashes
+     have been reported by a Windows user.  More generally, avoid
+     these extra calls if no joystick was detected.  */
+  if (joystick_detected == 0)
+    return;
+
   SDL_JoystickUpdate();
   if (joystick[0]) {
     joystick_b[0] = (joystick_b[0] & ~1) |

-- 
Alexandre Duret-Lutz





reply via email to

[Prev in Thread] Current Thread [Next in Thread]