Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
auth_update crash
Dec 23, 2017, 10:15 pm
By Remcon
check_tumble
Dec 18, 2017, 7:21 pm
By Remcon
parse description bug
Dec 15, 2017, 10:08 pm
By Remcon
Couple bugs
Dec 12, 2017, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Users Online
CommonCrawl, Yandex, Bing, Majestic-12

Members: 0
Guests: 12
Stats
Files
Topics
Posts
Members
Newest Member
478
3,708
19,242
612
Jacki72H
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » General » General Discussions » Interesting dilemna
Forum Rules | Mark all | Recent Posts

Interesting dilemna
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Apr 9, 2006, 12:14 pm
Go to the top of the page
Go to the bottom of the page

Kayle
Off the Edge of the Map
GroupAdministrators
Posts1,195
JoinedMar 21, 2006

OK, So I'm screwing around, trying to give the magey classes a way to have familiars, and such. And I've got it working perfect, it calls/summons the companion/familiar. Both the current skills work perfectly. Where my problem is, is with a particular familiar.

A level 50+ mage, of neutral alignment will summon an "ice serpent" and while this part works great. I was going through all the levels, and making sure that all the companions/familiars summoned right, I have to purge them after each one. But when I get to the ice serpent, it summons great, everythings perfect. But.. when I go to purge it.. the mud crashes. First I was like.. Hmm. Freak coincidence. So I booted back up and gave it another try. Same thing. Obviously, Now, it's no coincidence, so I boot back up in GDB, and do it again, and GDB spits out


Program received signal SIGSEGV, Segmentation fault.
0x400a418e in _int_free () from /lib/libc.so.6


Now, Occasionally, like.. 1 out of every 10 purges, it will actually purge the creature. but 9 out of 10 it crashes. So for the moment, I've warned everyone not to purge the ice serpent. So now, I turn to the collective knowledge contained here in these forums. And, To make things easier...

void do_summon_familiar( CHAR_DATA *ch, char *argument )
{
    MOB_INDEX_DATA *pMobIndex;
    CHAR_DATA *mount;
    int level;
	

   if( ch->pcdata->pet != NULL )
   {
       send_to_char( "You already have a familiar.\n\r", ch );
	   learn_from_failure( ch, gsn_summon_familiar );
       return;
   }
   if( ch->position == POS_FIGHTING )
   {
      send_to_char( "You can't concentrate enough for that!\n\r", ch );
	  learn_from_failure( ch, gsn_summon_familiar );
      return;
   }
    
   if( ( pMobIndex = get_mob_index( MOB_VNUM_FAMILIAR ) ) == NULL )
   {
    send_to_char( "The familiar mob doesn't exist.\n\r", ch );
    return;
   }
   
    do_sit( ch, "" );
    act( AT_MAGIC, "You begin to cast your spell to summon a familiar...", ch, NULL, NULL, TO_CHAR );
    act( AT_MAGIC, "$n begins to cast a spell to summon a familiar...", ch, NULL, NULL, TO_ROOM );
    WAIT_STATE( ch, 4 * PULSE_MOBILE);
    
         	
    mount = create_mobile( pMobIndex );
    
    mount->level = number_fuzzy( ( ch->level + ch->mod_cha ) / 2 );
    mount->mana = mount->max_mana = 0;
    mount->hit = mount->max_hit = number_fuzzy( ( ch->max_hit / 2 ) + ch->mod_cha );
    mount->armor = number_fuzzy( ch->armor - 10 );
    mount->hitroll = number_fuzzy( ch->level / 30) ;
    mount->damroll = number_fuzzy( ch->level / 30 );
    
    /* free up the old mob names */ 
    STRFREE( mount->description );
    STRFREE( mount->name );
    STRFREE( mount->short_descr );
    STRFREE( mount->long_descr );
    
    level = ch->level;
    
    if( level < 10 )
    {
        if IS_GOOD( ch )
        {
	    mount->description = 
	          str_dup( "You see a large snowy white owl. It's large, round, yellow eyes\n\r"
	                  "seem to pierce you to your very soul as it watches you closely.\n\r"
                      "You can't help but feel at peace as you behold this majestic bird.\n\r" );
	    mount->short_descr = str_dup( "a large snowy white owl" );
	    mount->long_descr = str_dup( "A large snowy white owl is here, watching for mice.\n\r" );
	    mount->name = str_dup( "familiar owl" );
		xSET_BIT( mount->attacks, ATCK_CLAWS );
		xSET_BIT( mount->affected_by, AFF_FLYING );
        }
        else if IS_NEUTRAL( ch )
        {
	    mount->description = 
	          str_dup( "You see a large midnight black raven. It's beady black eyes scan\n\r"
	                  "all around for anything shiny that would make a nice addition to it's\n\r"
                      "nest. As it notices you it lets out that familiar raven's caw.\n\r" );
	    mount->short_descr = str_dup( "a large raven" );
	    mount->long_descr = str_dup( "A large black bird is here, looking for shiney objects.\n\r" );
	    mount->name = str_dup( "familiar raven" );
		xSET_BIT( mount->attacks, ATCK_CLAWS );
		xSET_BIT( mount->affected_by, AFF_FLYING );
        }
        else
        {
	    mount->description = 
	          str_dup( "You see a humanoid skull, floating in mid-air. All the bones seem\n\r"
	                  "to be in perfect condition, and above all else, magically enhanced.\n\r"
                      "You can feel the hatred burning in the small flames in each of it's\n\r" 
                      "eyes.\n\r" );
	    mount->short_descr = str_dup( "a skull" );
	    mount->long_descr = str_dup( "A skull floats here, a fire burning in each eye socket.\n\r" );
	    mount->name = str_dup( "familiar skull" );
		xSET_BIT( mount->attacks, ATCK_BITE );
		xSET_BIT( mount->affected_by, AFF_FLYING );
        }
     }
    else if( level >= 10 && level < 20 )
    {
        if IS_GOOD( ch )
        {
	    mount->description = 
	          str_dup( "You see a small bird. It's grey-black, curved beak and black eyes,\n\r"
	                  "an uneven contrast to it's brilliant mixture of bright red, orange\n\r"
                      "and yellow plummage.\n\r" );
	    mount->short_descr = str_dup( "a corollax" );
	    mount->long_descr = str_dup( "A corollax is here, begging for tidbits of food.\n\r" );
	    mount->name = str_dup( "familiar corollax" );
		xSET_BIT( mount->attacks, ATCK_CLAWS );
		xSET_BIT( mount->affected_by, AFF_FLYING );
        }
        else if IS_NEUTRAL( ch )
        {
	    mount->description = 
	          str_dup( "You see a small winged cat. The tressym is no more than two feet in\n\r"
	                  "length and it's feathered leathery wings span out to almost three\n\r"
                      "feet. It's small amber eyes stare back at you as you regard it.\n\r" );
	    mount->short_descr = str_dup( "a Tressym" );
	    mount->long_descr = str_dup( "A small winged feline creature is here, observing all around it.\n\r" );
	    mount->name = str_dup( "familiar tressym" );
		xSET_BIT( mount->attacks, ATCK_CLAWS );
		xSET_BIT( mount->affected_by, AFF_SNEAK );
        }
        else
        {
	    mount->description = 
	          str_dup( "You see a tiny humanoid, with batlike wings, a long barbed tail and\n\r"
	                  "sharp twisted horns protuding from it's skull. It's skin is a deep\n\r"
                      "red and its twisted horns and sharp teeth are a gleaming white.\n\r" );
	    mount->short_descr = str_dup( "a mischievous imp" );
	    mount->long_descr = str_dup( "An imp is here, grinning mischievously.\n\r" );
	    mount->name = str_dup( "familiar imp" );
		xSET_BIT( mount->attacks, ATCK_DRAIN );
		xSET_BIT( mount->affected_by, AFF_FLYING );
		xSET_BIT( mount->defenses, DFND_FIRESHIELD );
        }
     }
    else if( level >= 20 && level < 30 )
    {
        if IS_GOOD( ch )
        {
	    mount->description = 
	          str_dup( "You see a short, pig-faced creature with green wart covered skin.\n\r"
	                  "It's small wings span about two feet and it's small mouth is full\n\r"
                      "of tiney needle-like teeth dripping with a poison.\n\r" );
	    mount->short_descr = str_dup( "a small homunculus" );
	    mount->long_descr = str_dup( "A small homunculus is here, scrambling about.\n\r" );
	    mount->name = str_dup( "familiar homunculus" );
		xSET_BIT( mount->attacks, ATCK_BITE );
		xSET_BIT( mount->attacks, ATCK_POISON );
		xSET_BIT( mount->affected_by, AFF_FLYING );
        }
        else if IS_NEUTRAL( ch )
        {
	    mount->description = 
	          str_dup( "You see something that resembles a sick cross between a bat and a\n\r"
	                  "giant mosquito. It's membranous wings, short furry body, and eight\n\r"
                      "jointed legs are a virbrant red color.\n\r" );
	    mount->short_descr = str_dup( "a stirge" );
	    mount->long_descr = str_dup( "A stirge is here, buzzing about annoyingly.\n\r" );
	    mount->name = str_dup( "familiar stirge" );
		xSET_BIT( mount->attacks, ATCK_FEED );
		xSET_BIT( mount->affected_by, AFF_FLYING );
        }
        else
        {
	    mount->description = 
	          str_dup( "You see a tiny humanoid, with batlike wings, a long barbed tail and\n\r"
	                  "sharp twisted horns protuding from it's skull. It's skin is a pustulent\n\r"
                      "green and its twisted horns and sharp teeth are a gleaming white.\n\r" );
	    mount->short_descr = str_dup( "an insidious quasit" );
	    mount->long_descr = str_dup( "A quasit is here, looking rather insidious.\n\r" );
	    mount->name = str_dup( "familiar quasit" );
		xSET_BIT( mount->attacks, ATCK_DRAIN );
		xSET_BIT( mount->affected_by, AFF_FLYING );
		xSET_BIT( mount->defenses, DFND_FIRESHIELD );
        }
     }
    else if( level >= 30 && level < 40 )
    {
        if IS_GOOD( ch )
        {
	    mount->description = 
	          str_dup( "You see a large canine creature, with yellow-brown fur. It's much\n\r"
	                  "larger than most other wild dogs and appears to be in possession\n\r"
                      "of the ability to teleport around.\n\r" );
	    mount->short_descr = str_dup( "a blink dog" );
	    mount->long_descr = str_dup( "A blink dog is here, teleporting about the immediate area.\n\r" );
	    mount->name = str_dup( "familiar blink dog" );
		xSET_BIT( mount->attacks, ATCK_BASH );
		xSET_BIT( mount->affected_by, AFF_PASS_DOOR );
        }
        else if IS_NEUTRAL( ch )
        {
	    mount->description = 
	          str_dup( "You see a small, sleek reptile whose body is coursing with pure\n\r"
	                  "electricity. It has a bullet shaped head sporting a pair of slender\n\r"
                      "horns that sweep back like ears. Its tail is covered in tiny spikes.\n\r" );
	    mount->short_descr = str_dup( "a shocker lizard" );
	    mount->long_descr = str_dup( "A lizard coursing with electricity is here, waving its spiked tail.\n\r" );
	    mount->name = str_dup( "familiar shocker lizard" );
		xSET_BIT( mount->attacks, ATCK_TAIL );
		xSET_BIT( mount->affected_by, AFF_SHOCKSHIELD );
        }
        else
        {
	    mount->description = 
	          str_dup( "This tiny beholderkin is no more than eight in width. It has a\n\r" 
	                  "large central eye, and several smaller eyestalks atop its orb,\n\r"
                      "much like true beholders.\n\r" );
	    mount->short_descr = str_dup( "an eyeball beholderkin" );
	    mount->long_descr = str_dup( "A small beholderkin floats menacingly about here.\n\r" );
	    mount->name = str_dup( "familiar eyeball beholderkin" );
		xSET_BIT( mount->attacks, ATCK_HARM );
		xSET_BIT( mount->affected_by, AFF_FLOATING );
        }
     }
    else if( level >= 40 && level < 50 )
    {
        if IS_GOOD( ch )
        {
	    mount->description = 
	          str_dup( "This small reddish-brown dragon looks like a miniature red dragon.\n\r"
	                  "It has fine scales and sharp horns and teeth. It flexes its barbed\n\r"
                      "flexible tail and lets out a low purr as it sees you regarding it.\n\r" );
	    mount->short_descr = str_dup( "a pseudodragon" );
	    mount->long_descr = str_dup( "A dragon flitters about here.\n\r" );
	    mount->name = str_dup( "familiar pseudodragon dragon" );
		xSET_BIT( mount->attacks, ATCK_TAIL );
		xSET_BIT( mount->affected_by, AFF_FLYING );
        }
        else if IS_NEUTRAL( ch )
        {
	    mount->description = 
	          str_dup( "You see a giant bird that reminds you of a featherless ostrich. It\n\r"
	                  "stands about eight feet tall and has a mottled dusky red skin.\n\r"
                      "Steam constantly pours from it's nose and beak.\n\r" );
	    mount->short_descr = str_dup( "a giant strider" );
	    mount->long_descr = str_dup( "A giant strider is here, steam billowing form its beak and nose.\n\r" );
	    mount->name = str_dup( "familiar giant strider" );
		xSET_BIT( mount->attacks, ATCK_FIREBALL );
		xSET_BIT( mount->affected_by, AFF_FIRESHIELD );
        }
        else
        {
	    mount->description = 
	          str_dup( "You see a large bat-like creature with a seven foot wingspan, and\n\r"
	                  "a huge, triangular, razor-sharp tail. Its velvet black fur is a\n\r"
                      "perfect contrast with its violet eyes.\n\r" );
	    mount->short_descr = str_dup( "a night hunter bat" );
	    mount->long_descr = str_dup( "A massive bat, dark as night, is here hunting for prey.\n\r" );
	    mount->name = str_dup( "familiar night hunter bat" );
		xSET_BIT( mount->attacks, ATCK_BITE );
		xSET_BIT( mount->affected_by, AFF_FLYING );
        }
     }
    else
    {
        if IS_GOOD( ch )
        {
	    mount->description = 
	          str_dup( "This monstrous serpent bears massive feathered wings, with feathers\n\r"
	                  "the colors of the rainbow. It's huge body appears to be at least 12\n\r"
                      "feet long, and it's wings span about 15 feet.\n\r" );
	    mount->short_descr = str_dup( "a beautiful couatl" );
	    mount->long_descr = str_dup( "A beautiful couatl is here, gliding effortlessly through the air.\n\r" );
	    mount->name = str_dup( "familiar couatl" );
		xSET_BIT( mount->attacks, ATCK_BITE );
		xSET_BIT( mount->attacks, ATCK_TAIL );
		xSET_BIT( mount->affected_by, AFF_FLYING );
        }
        else if IS_NEUTRAL( ch )
        {
	    mount->description = 
	          str_dup( "You see a wait.. Where'd it go?!\n\r"
	                  "The ice serpent is a naturally invisible serpent made of frigid air\n\r"
                      "that is constantly in motion and stirs up dust and dirt to make\n\r"
                      "itself visible.\n\r" );
	    mount->short_descr = str_dup( "an ice serpent" );
	    mount->long_descr = str_dup( "A cloud of dust and shards of ice come together in the form of a serpent.\n\r" );
	    mount->name = str_dup( "familiar ice serpent" );
		xSET_BIT( mount->attacks, ATCK_FROSTBREATH );
		xSET_BIT( mount->attacks, ATCK_TAIL );
		xSET_BIT( mount->affected_by, AFF_INVISIBLE );
		xSET_BIT( mount->affected_by, AFF_ICESHIELD );
        }
        else
        {
	    mount->description = 
	          str_dup( "You see before you a being distorted by madness. It looks vaguely\n\r"
	                  "humanoid, but from the waist down it trails off into vaporous\n\r"
                      "nothingness, leaving a trail of fog as it moves.\n\r" );
	    mount->short_descr = str_dup( "an allip" );
	    mount->long_descr = str_dup( "An allip is here, leting out a low moan.\n\r" );
	    mount->name = str_dup( "familiar allip" );
		xSET_BIT( mount->attacks, ATCK_DRAIN );
		xSET_BIT( mount->affected_by, AFF_FLYING );
		xSET_BIT( mount->affected_by, AFF_PASS_DOOR );
        }
     }
	
    
    
    char_to_room( mount, ch->in_room );
    act( AT_PLAIN, "$N appears, summoned by your spell.", ch, mount, mount, TO_CHAR );
    act( AT_PLAIN, "$N appears, summoned by $n's spell.", ch, mount, mount, TO_ROOM );
    learn_from_success( ch, gsn_summon_familiar );
    add_follower( mount, ch );
    mount->leader = ch;
    ch->pcdata->pet = mount;
    do_stand( ch, "" );

    xSET_BIT( mount->act, ACT_PET );
    xSET_BIT( mount->affected_by, AFF_CHARM );
    ch->move -= (mount->level / 2);  /* physically draining loss of moves */
    return;
}

That's the summon familiar skill. It's currently running on a Modified SmaugFUSS 1.7 and yeah, thanks in advance for any help :)
       
Post is unread #2 Apr 9, 2006, 1:21 pm
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,868
JoinedJul 26, 2005



Program received signal SIGSEGV, Segmentation fault.
0x400a418e in _int_free () from /lib/libc.so.6


This alone just lets us know that it likly tried to free/dispose of something that was NULL or invalid
Get it to crash again while your in gdb, when it does crash.
Try typing in
bt
that should at least give us some more info about what the problem is.
       
Post is unread #3 Apr 9, 2006, 1:30 pm
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,868
JoinedJul 26, 2005

but from the code you posted you do have something not right :)
    /* free up the old mob names */ 
    STRFREE( mount->description );
    STRFREE( mount->name );
    STRFREE( mount->short_descr );
    STRFREE( mount->long_descr );
    
    level = ch->level;
    
    if( level < 10 )
    {
        if IS_GOOD( ch )
        {
        mount->description = 
              str_dup( "You see a large snowy white owl. It's large, round, yellow eyes\n\r"
                      "seem to pierce you to your very soul as it watches you closely.\n\r"
                      "You can't help but feel at peace as you behold this majestic bird.\n\r" );
        mount->short_descr = str_dup( "a large snowy white owl" );
        mount->long_descr = str_dup( "A large snowy white owl is here, watching for mice.\n\r" );
        mount->name = str_dup( "familiar owl" );
        xSET_BIT( mount->attacks, ATCK_CLAWS );
        xSET_BIT( mount->affected_by, AFF_FLYING );
        }

This is just a sample of it.
Your using str_dup when setting all of the stuff, but you used STRFREE to dispose of all the stuff
you should probably take a look at what most name, long_descr, short_descr and description's are for stuff
if they use str_dup they use DISPOSE if they use STRALLOC they use STRFREE
Stock wise unless you have changed it fully those all should use STRALLOC and STRFREE
your lucky if only one of them is crashing.
So change all the str_dup in that function to STRALLOC instead
       
Post is unread #4 Apr 9, 2006, 2:21 pm
Go to the top of the page
Go to the bottom of the page

Kayle
Off the Edge of the Map
GroupAdministrators
Posts1,195
JoinedMar 21, 2006

Yeah.. that fixed it .. I feel like a 'tard now. I shoulda caught that. Now it's been summoned and purged 50 times each (Gotta love triggers) and not a single crash. Thanks Remcon.
       
Post is unread #5 Apr 9, 2006, 3:45 pm
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,868
JoinedJul 26, 2005

Don't feel bad, we all make mistakes lol.
Your welcome.
       
Post is unread #6 Apr 9, 2006, 7:41 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

The STRFREE/DISPOSE thing gets old quickly. There really should be a single macro set for that. Or just handle all strings with the hash code. Last time I did that it didn't take up any more memory.
       
Post is unread #7 Apr 11, 2006, 1:04 pm
Go to the top of the page
Go to the bottom of the page

Halcyon
Magician
GroupMembers
Posts187
JoinedApr 12, 2005

I had done that once myself, I think the extra memory usage was almost indiscernable. Perhaps it is time to drop the unhashed functions and macros? It seems to me that they've outlived their usefulness, and moreover, only cause problems at this point.
       
Post is unread #8 Apr 13, 2006, 4:37 pm
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,868
JoinedJul 26, 2005

Well using the non hash method does indead have one good point, it makes it way easier to detect memory leaks using valgrind :), personaly I to suggest using STRALLOC and STRFREE on everything when possible :)
       
Pages:<< prev 1 next >>