Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
Couple bugs
Dec 12, 2017, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
Bug in will_fall( )
Oct 23, 2017, 1:35 am
By GatewaySysop
Bug in do_zap( ), do_brandish( )
Oct 18, 2017, 1:52 pm
By GatewaySysop
Bug in get_exp_worth( )
Oct 10, 2017, 1:26 am
By GatewaySysop
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
Memwatch
Author: Johan Lindh
Submitted by: Vladaar
Users Online
CommonCrawl, Yandex, Sogou, Bing, DotBot, Google

Members: 0
Guests: 8
Stats
Files
Topics
Posts
Members
Newest Member
477
3,705
19,232
608
LAntorcha
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Codebases » SWR FUSS » Issue with space v2
Forum Rules | Mark all | Recent Posts

Issue with space v2
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 May 18, 2010, 4:36 am
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

I decided to incorporate this into my mud a few days ago and finally got through all the compiler errors. One thing I noticed though was that there were no parts for the ships actually created. They were all in the prototype files that came with the source as samples. So I decided to create a parts creation command. This is where I'm having the problem.

I have it set up to do a couple of things but any time I try to do something with the parts name other than set it, the mud crashes when strlen is called. This happens any time I try to display it or save it and I can not figure out why.

Here's some relevant bits and pieces of code to show what I'm doing so someone can hopefully figure out what I'm doing wrong.

The part_data structure in mud.h:
struct part_data
{
   PART_DATA * next;
   PART_DATA * prev;
   PAYLOAD_DATA * first_payload;
   PAYLOAD_DATA * last_payload;
   PAYLOAD_DATA * firing;
   TIMER * first_timer;
   TIMER * last_timer;
   char * name;
   int v1;
   int v2;
   int v3;
   int v4;
   int v5;
   int v6;
   int hit;
   int maxhit;
   int cost;
   float size;
   short type;
   short count;
   short fired;
   bool military;
};

The part_table in ships.cpp:
const unsigned short MAX_SHIP_PARTS(256);
struct part_data part_table[MAX_SHIP_PARTS];

Function to save the part table to file:
void save_part_table()
{
   FILE *fp;
   char filename[MAX_STRING_LENGTH];

   sprintf(filename,"%sparts.lst",SHIP_PROTOTYPE_DIR);
   if ( ( fp = FileOpen( filename, "w" ) ) == NULL )
   {
      perror( filename );
      return;
   }
   for( int x = 0; x <= MAX_SHIP_PARTS; ++x )
   {
      fprintf( fp, "#PART\n" );
      fprintf( fp, "Name     %s~\n",   part_table[x].name );     <--- Craps out here
      fprintf( fp, "Hit      %d\n",    part_table[x].hit );
      fprintf( fp, "Maxhit   %d\n",    part_table[x].maxhit );
      fprintf( fp, "Cost     %d\n",    part_table[x].cost );
      fprintf( fp, "Type     %d\n",    part_table[x].type );
      fprintf( fp, "Restrict %d\n",    part_table[x].military );
      fprintf( fp, "Size     %1.1f\n", part_table[x].size );
      fprintf( fp, "V1       %d\n",    part_table[x].v1 );
      fprintf( fp, "V2       %d\n",    part_table[x].v2 );
      fprintf( fp, "V3       %d\n",    part_table[x].v3 );
      fprintf( fp, "V4       %d\n",    part_table[x].v4 );
      fprintf( fp, "V5       %d\n",    part_table[x].v5 );
      fprintf( fp, "V6       %d\n",    part_table[x].v6 );
      fprintf( fp, "#ENDPART\n";);
   }
   fprintf(fp,"END\n";);
   FileClose( fp );
}

Piece of the do_editpart function for displaying the parts:
if( !str_cmp(arg, "list";) )
{
   if ( argument[0] == '\0' )
   {
      send_to_char( "Current complete list of parts.\r\n", ch );
      send_to_char("*************************************************************************\r\n", ch );
      for ( short x = 0; x < MAX_SHIP_PARTS; ++x )
      {
         if( part_table[x].name != '\0' )
            ch_printf( ch, "%-3d) Name: %-15s Hit: %-5d Maxhit: %-5d Cost: %-6 Type: %-7s Size: %-1.1f MIL: %c\r\n",
            ( x + 1 ), part_table[x].name, part_table[x].hit, part_table[x].maxhit, part_table[x].cost,
            part_types[part_table[x].type], part_table[x].size, part_table[x].military == true ? 'Y' : 'N' );
      }
      send_to_char("*************************************************************************\r\n", ch );
      return;
   }
...there's some more stuff down here under the list option for displaying a list of specific part types, such as shields but it's more
or less exactly the same. And it dies on the call to ch_printf as well :(

And another sectiont of do_editpart for setting a parts name:
if( !str_cmp(arg, "name";) )
{
   if( argument[0] == '\0' )
   {
      send_to_char( "You need to specify a name for your new part.\r\n", ch );
      return;
   }
   part_table[part].name = STRALLOC(argument);
   ch_printf( ch, "New part name is %s.\r\n", argument );
   return;
}
Setting the name seems to work just fine.

I've run it through gdb a few times trying to figure out what's going on and it seems to be setting the name just fine. I can print it out in there no problem, but any attempt to do something with it in-game, after the name has been set, and down comes the mud.

So, any ideas?
       
Post is unread #2 May 19, 2010, 4:41 am
Go to the top of the page
Go to the bottom of the page

Sharmair
Fledgling
GroupMembers
Posts7
JoinedApr 19, 2010

A gdb backtrace of a specific crash might be helpful to start really figuring out
what is going on. From the way you are saying things, it sounds like you are
having crashes in more then one place and it is a bit unclear what data you
give goes with what.

But, strlen can be crashed with a NULL or invalid pointer, so I would think that
would be a clue. Doing a quick look, I see a number of things wrong, some
might cause a crash, and others probably not:
The loop in your save should be < MAX_SHIP_PARTS not <= (might crash).
The ch_printf in the list has %-6 for the cost (missing a d?)( could crash).
Your name set does not STRFREE the old name if one is set (should not crash).
       
Post is unread #3 May 19, 2010, 4:32 pm
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

Hmm. Thanks for pointing those things out.

Well now. After taking care of those issues it seems to be working.
Thanks a lot! :)
       
Pages:<< prev 1 next >>