Crash on closing..

Posted by Nick Cash on Sun 08 Jun 2003 10:36 AM — 4 posts, 17,856 views.

USA #0
Alright, I've tried to install a locker code into my mud, and it has worked perfectly except for one thing. They cannont close the locker, and I know how unspecific that can be so I'll post the closing code here. Then if I must I will post additional code such as the fwrite_locker and such. It only crashes on closing the locker by the way.

From the do_locker function:

else if( !str_cmp( arg, "close" ) ) 
    {
        if( !ch->pcdata->locker )
        {
            send_to_char( "You are not currently in the locker room.\r\n", ch );
            return;
        }
        
    	locker = ch->pcdata->locker;

        /* Total the weight of the contents */
        locker->holding = 0;
        
        for( obj = ch->in_room->first_content; obj; obj = obj->next_content )
        {
            locker->holding = locker->holding + obj->weight;

            if( obj->item_type == ITEM_CONTAINER )
            {
                send_to_char( "You may not leave containers in the locker room.\r\n", ch );
                return;
            } 
        }

        if( locker->holding > locker->capacity )
        {
            sprintf( buf, "The weight limit of your locker has beed exceeded.  "
                          "You must carry\r\nsome items out when you leave.\r\n" );
            send_to_char( buf, ch );
            return;
        } 
        
        /* Save the locker */
        fwrite_locker( ch );

        /* Return the player to the real world. */ 
        char_from_room( ch );
        char_to_room( ch, get_room_index( ch->pcdata->locker_vnum ) );

        delete_locker( ch );

        do_look( ch, "auto" );
        send_to_char( "Your locker has been closed and saved.\r\n", ch );
       }    
    else
    {
        send_to_char( "Syntax: locker <open | close>\r\n", ch );
        return;
    }
       
    return;    
}


Trying to find where the error really is I added in send_to_char statements before delete_locker and fwrite_locker, assuming that they would show up before it crashed. Assuming that would work right, and it always has before, then those functions are clean because it crashes before either come up. Perhaps a problem with the for loop? I'm not sure, please help :)
Amended on Sun 08 Jun 2003 10:38 AM by Nick Cash
USA #1
Hmm, this is one of those bugs that doesn't jump out at you very clearly. It could be a number of problems not directly rlated to this bit of code as well. You really should run GDB on this error. Since it's reproduceable you should be able to find the problem easy enough. Also, have you tried "triggering" any of the returns? i.e. dropping a container or 'exceeding the weight limit' ? That's always a good place to start. It'll give you an idea of where the crash is occuring.

If I had to guess.
I'd say these lines are your prime targets:

/* Save the locker */
        fwrite_locker( ch );

        /* Return the player to the real world. */ 
        char_from_room( ch );
        char_to_room( ch, get_room_index( ch->pcdata->locker_vnum ) );

        delete_locker( ch );



GDB is your friend ;-)
USA #2
Strange memories of having seen locker problems before when I was helping with Resortmud.... hmmm. I forget how they fixed it but it looks like you have the same code. Might want to ask them :)
USA #3
Now, I got it fixed, and I'm sure your all wondering how! Or not, doesn't matter. Anyways, thanks Samson. I just downloaded they beta version and stuck their locker.c where mine used to be and with my modifications I needed it worked like a charm. Anyways, thanks!