Segfault in learn_from_success and learn_from_failure

Posted by Robert Powell on Fri 27 Jun 2014 06:53 AM — 5 posts, 21,500 views.

Australia #0
I am not sure what is happening here: Namely why adept is in the millions when it should be 95 at most.


Program received signal SIGSEGV, Segmentation fault.
0x00000000005d8ace in learn_from_success (ch=0xc426a0, sn=-1) at skills.c:1835
1835	   adept = GET_ADEPT( ch, sn );
(gdb) list
1830	   
1831	  
1832	
1833	   if( IS_NPC( ch ) || ch->pcdata->learned[sn] <= 0 )
1834	      return;
1835	   adept = GET_ADEPT( ch, sn );
1836	   sklvl = skill_table[sn]->skill_level[ch->Class];
1837	   if( sklvl == 0 )
1838	      sklvl = ch->level;
1839	   if( ch->pcdata->learned[sn] < adept )
(gdb) print adept
$19 = 178727773
(gdb) print ch
$20 = (CHAR_DATA *) 0xc426a0
(gdb) print sn
$21 = -1
(gdb) print sklvl
$22 = 32
(gdb) print ch->level
$23 = 65
(gdb) print ch->pcdata->learned[sn]
$24 = 75
(gdb) 




void learn_from_success( CHAR_DATA * ch, int sn )
{
   int adept, gain, sklvl, learn, percent, schance;
   
  

   if( IS_NPC( ch ) || ch->pcdata->learned[sn] <= 0 )
      return;
   adept = GET_ADEPT( ch, sn );
   sklvl = skill_table[sn]->skill_level[ch->Class];
   if( sklvl == 0 )
      sklvl = ch->level;
   if( ch->pcdata->learned[sn] < adept )
   {
      schance = ch->pcdata->learned[sn] + ( 5 * skill_table[sn]->difficulty );
      percent = number_percent(  );
      if( percent >= schance )
         learn = 2;
      else if( schance - percent > 25 )
         return;
      else
         learn = 1;
      ch->pcdata->learned[sn] = UMIN( adept, ch->pcdata->learned[sn] + learn );
      if( ch->pcdata->learned[sn] == adept ) /* fully learned! */
      {
         gain = 1000 * sklvl;
         
         set_char_color( AT_WHITE, ch );
         ch_printf( ch, "You are now an adept of %s!  You gain %d bonus experience!\r\n", skill_table[sn]->name, gain );
      }
      else
      {
         gain = 100 * sklvl;
         
         if( !ch->fighting && sn != gsn_hide && sn != gsn_sneak )
         {
            set_char_color( AT_WHITE, ch );
            ch_printf( ch, "You gain %d experience points from your success!\r\n", gain );
         }
      }
      gain_exp( ch, gain );
   }
}
Amended on Fri 27 Jun 2014 06:58 AM by Robert Powell
USA #1
I'm not seeing anything there that should be causing any issues. My best guess would be you're getting a bad reference from GET_ADEPT and we probably need to be looking at the code behind that call rather than this function.
Australia #2
Meerclar said:

I'm not seeing anything there that should be causing any issues. My best guess would be you're getting a bad reference from GET_ADEPT and we probably need to be looking at the code behind that call rather than this function.


Yeah I did a bit more digging and when i tried to print difficulty, found that its memory was unreachable. Started stepping backwards and found it all came down to a new auto defence skill I added 'Pirouette' much like dodge etc,

ASSIGN_GSN( gsn_pirouette, "pirouette" ); but spelled the skill pirouete in skills.dat :)

One typo cost me a few hours of wondering and stuffing about, now that this is sorted out, I can get back to what I was doing.
USA #3
Sounds like my login script issues earlier in the week - strcmp between lowercase in the first list and uppercase in the second location. I'm sure you know how well that worked out.
Australia #4
Meerclar said:

Sounds like my login script issues earlier in the week - strcmp between lowercase in the first list and uppercase in the second location. I'm sure you know how well that worked out.


I bet it worked out dismally and took you hours of debugging to work out why it was all wrong :)