Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ segmentation fault, tried GDB, failed miserably.

segmentation fault, tried GDB, failed miserably.

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Will Sayin   USA  (17 posts)  Bio
Date Mon 27 Jun 2005 08:23 AM (UTC)
Message
OK, right now I am just messing around with SMAUG-FUSS in CYGWIN, and I decided to make a new skill, with new code and everything. Now, just so you know, I am new to coding, I have dabbled for a while, but I have never delved into something so intricate as SMAUG.

I added the following code:

(the code is supposed to stop combat(like flee) then cause the user to go into hide, but will only work if the victim is affected by blindness)


void do_retreat( CHAR_DATA * ch, char *argument )
{
   int percent;
   CHAR_DATA *victim;
   if( ch->fighting )
   {
        percent = number_percent(  ) + ( IS_AFFECTED( victim, AFF_BLIND ) ? 10 : -50 )
      - ( get_curr_lck( ch ) - 15 ) + ( get_curr_lck( victim ) - 13 );
        if( !IS_AFFECTED( victim, AFF_BLIND ) || !can_use_skill( ch, percent, gsn_retreat ))
        {
            send_to_char( "You try to jump out of combat, but are unable to get out in time!\n\r", ch );
            act(AT_ACTION, "$n tries to jump out of combat, but you catch $m!", ch, NULL, victim, TO_VICT );
            act(AT_ACTION, "$n tries to jump out of combat, but $N catches $m!", ch, NULL, victim, TO_NOTVICT );
            WAIT_STATE( ch, 15 );
            return;
        }
        
        stop_fighting( ch, TRUE );
        xSET_BIT( ch->affected_by, AFF_HIDE );
        send_to_char( "You jump out of combat and seek refuge in the shadows.\n\r", ch);
        WAIT_STATE( ch, 10);
   }
        
            
}           

to skills.c

this to tables.c:(line 2098)


if( skill == do_retran )
      return "do_retran";
   if( skill == do_retreat )  <------these two
      return "do_retreat";    <------   lines
   if( skill == do_return )   
      return "do_return";


as well as this to tables.c:(line 966)

if( !str_cmp( name, "do_retran" ) )
            return do_retran;
         if( !str_cmp( name, "do_retreat") ) <--- this line
            return do_retreat;               <--- and this
         if( !str_cmp( name, "do_return" ) )
            return do_return;


in mud.h, line 3905:

DECLARE_DO_FUN( do_retran );
DECLARE_DO_FUN( do_retreat ); <----- this line
DECLARE_DO_FUN( do_return );




when I fight a mob, gouge them, and type retreat, a segmentation fault occurs. I was able to get this much with GDB:


Program received signal SIGSEGV, Segmentation fault.
0x004c3eea in get_Trust (ch=0x440f708) at handler.c:136
136        if( ch->trust !=0 )
(gdb) list
131 short get_trust( CHAR_DATA * ch )
132{
133   if( ch->desc && ch->desc->original )
134      ch = ch->desc->original;
135
136   if( ch->trust != 0 )
137      return ch->trust;
138
139   if( IS_NPC( ch ) && ch->level >= LEVEL_AVATAR )
140      return LEVEL_AVATAR;
141
142   if( ch->level >= LEVEL_NEOPHYTE && IS_RETIRED( ch ) )
143      return LEVEL_NEOPHYTE;
144
145   return ch->level;
146   }
(gdb) print ch->trust
Cannot access memory at address 0x440f7c0
(gdb)


Thanks to Nick Gammon's GDB tutorial, I have figured out that this has something to do with ch->trust(I hope!)... just what, I have no clue.

Could anyone help give me some idea of what is going on, and how I could fix it?

Thanks a lot,
Will Sayin
telnet://darkstone.betterbox.net:5432

Will Sayin
Developer, Legends of the Darkstone
www.darkstonemud.com:5432
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #1 on Mon 27 Jun 2005 07:34 PM (UTC)
Message
Hi there. :)

You also need to look at the backtrace from GDB, that is, a path of function calls that will tell you how you got there.

One problem, probably the culprit, is that you declare 'victim' but you never set it to anything. You probably meant to set it to whomever ch is fighting.

The error you're getting looks like ch is bad somehow in get_trust. My hunch is that one of the functions you're calling with uninitialized 'victim' as a parameter is dying. A backtrace will help you out there; and also you can type 'up' and 'down' to navigate the backtrace. That way you know exactly what line of code was being run and where.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Will Sayin   USA  (17 posts)  Bio
Date Reply #2 on Mon 27 Jun 2005 09:25 PM (UTC)
Message
Thanks Ksilyan,

I looked at do_gouge and copy/pasted:

victim = who_fighting( ch );


and it all worked fine from there.

Thank You,
Will Sayin
telnet://darkstone.betterbox.net:5432

Will Sayin
Developer, Legends of the Darkstone
www.darkstonemud.com:5432
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


14,298 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.