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 ➜ Silly asteroids...

Silly asteroids...

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


Pages: 1 2  3  4  

Posted by Nick Cash   USA  (626 posts)  Bio
Date Sun 28 Mar 2004 07:05 AM (UTC)
Message
Ok, kind of weird, look at this:

Sat Mar 27 22:55:51 2004 :: Loading asteroids...
Sat Mar 27 22:55:51 2004 :: [*****] BUG: fread_word: EOF encountered on read.

Sat Mar 27 22:55:51 2004 :: [*****] BUG: Cannot load asteroid file: ÿ


I know for a fact there is no asteroid with the name ÿ. So, any clues to why it might be giving me this error every time it starts?

Note: Using heavily modified SWR 1.0 and this asteroid code is all custom.

~Nick Cash
http://www.nick-cash.com
Top

Posted by Kris   USA  (198 posts)  Bio
Date Reply #1 on Mon 29 Mar 2004 07:32 PM (UTC)
Message
It's most likely caused by a problem with the variable type itself, or with the method by which you're reading the file. Could you post the file I/O code for it?
Top

Posted by Nick Cash   USA  (626 posts)  Bio
Date Reply #2 on Mon 29 Mar 2004 10:50 PM (UTC)

Amended on Mon 29 Mar 2004 10:51 PM (UTC) by Nick Cash

Message
Ok, this is the one. Of course like traditional file reading there are several functions involved, but this is the one in this instance me thinks.

/*
 * Load in all the asteroid files.
 */
void load_asteroids( )
{
    FILE *fpList;
    char *filename;
    char astlist[256];
    char buf[MAX_STRING_LENGTH];


    first_asteroid      = NULL;
    last_asteroid       = NULL;

    sprintf( astlist, "%s%s", AST_DIR, AST_LIST );
    fclose( fpReserve );
    if ( ( fpList = fopen( astlist, "r" ) ) == NULL )
    {
        perror( astlist );
        exit( 1 );
    }

    for ( ; ; )
    {

        filename = feof( fpList ) ? "$" : fread_word( fpList );

        if ( filename[0] == '$' )
          break;

        if ( !load_asteroid_file( filename ) )
        {
          sprintf( buf, "Cannot load asteroid file: %s", filename );
          bug( buf, 0 );
        }

    }
    fclose( fpList );
    log_string(" Done asteroids" );
    fpReserve = fopen( NULL_FILE, "r" );
    return;
}

~Nick Cash
http://www.nick-cash.com
Top

Posted by Greven   Canada  (835 posts)  Bio
Date Reply #3 on Mon 29 Mar 2004 10:54 PM (UTC)
Message
You might double check the asteroid list file to make sure that everything in it is right, that you have a $ at the end of the file, for example.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
Top

Posted by Samson   USA  (683 posts)  Bio
Date Reply #4 on Tue 30 Mar 2004 12:57 AM (UTC)
Message
Also, as stupid as this may sound - open the file in pico on a *nix machine. Go to the end. HIt backspace until you're right next to the last character in the file. Then hit enter once and resave it. Often that alone is all it takes to stop the funky symbols from showing up in the logs.
Top

Posted by Nick Cash   USA  (626 posts)  Bio
Date Reply #5 on Tue 30 Mar 2004 02:59 AM (UTC)
Message
Ok, found out something more. If I delete all of the asteroids and start a new everything goes correctly with no asteroids. If I make an asteroid and reboot I get the same error. I'm thinking it must be something with saving the asteroid. Also, if I use do_showasteroid on it, it hangs up on the line where its either showing the starsystem's name or its home starsystem (a char variable). This is set to Terra as default (STRALLOC("Terra")). Perhaps I've got the STRALLOC/str_dup thing wrong again. Would you all mind clearing that up again? DISPOSE goes with str_dup? Or what.

Thanks.

~Nick Cash
http://www.nick-cash.com
Top

Posted by Samson   USA  (683 posts)  Bio
Date Reply #6 on Tue 30 Mar 2004 12:42 PM (UTC)
Message
STRALLOC goes with STRFREE and is used for hashed, or shared strings.

str_dup goes with DISPOSe and is used for nonhashed, or unique strings.

This should have no bearing on why your file is adding extra junk to the end of it. Could you post the function which saves the asteroid file?
Top

Posted by Nick Cash   USA  (626 posts)  Bio
Date Reply #7 on Tue 30 Mar 2004 11:38 PM (UTC)

Amended on Tue 30 Mar 2004 11:40 PM (UTC) by Nick Cash

Message
I just wanted to have it cleared up again, thats all. Here is save_asteroid:

/*
 * Save asteroid to a data file
 */
void save_asteroid( ASTEROID_DATA *asteroid )
{
    FILE *fp;
    char filename[256];
    char buf[MAX_STRING_LENGTH];

    if ( !asteroid )
    {
	bug( "save_asteroid: Null asteroid pointer!", 0 );
	return;
    }
        
    if ( !asteroid->filename || asteroid->filename[0] == '\0' )
    {
	sprintf( buf, "save_asteroid: %s has no filename", asteroid->name );
	bug( buf, 0 );
	return;
    }
 
    sprintf( filename, "%s%s", AST_DIR, asteroid->filename );
    
    fclose( fpReserve );
    if ( ( fp = fopen( filename, "w" ) ) == NULL )
    {
    	bug( "save_asteroid: fopen", 0 );
    	perror( filename );
    }
    else
    {
	fprintf( fp, "#ASTEROID\n" );
	fprintf( fp, "Name         %s~\n",	asteroid->name			);
	fprintf( fp, "Filename     %s~\n",	asteroid->filename		);
	fprintf( fp, "Home         %s~\n",  	asteroid->home_system   	);
	fprintf( fp, "Type         %d\n",	asteroid->type			);
	fprintf( fp, "Stype        %d\n",	asteroid->stype			);
	fprintf( fp, "Hp           %d\n",	asteroid->hp			);
	fprintf( fp, "Maxhp        %d\n",	asteroid->maxhp			);
	fprintf( fp, "Speed        %d\n",	asteroid->speed			);
	fprintf( fp, "Timer	   %d\n",	asteroid->timer			);
	fprintf( fp, "End\n\n"			);
	fprintf( fp, "#END\n"			);
    }
    fclose( fp );
    fpReserve = fopen( NULL_FILE, "r" );
    return;
}

~Nick Cash
http://www.nick-cash.com
Top

Posted by Nick Gammon   Australia  (23,162 posts)  Bio   Forum Administrator
Date Reply #8 on Wed 31 Mar 2004 06:40 AM (UTC)
Message
What data is actually written to the asteroid file? Complete junk? Or valid data with a ÿ at the end? BTW I think ÿ is hex FF, that sounds suspicious.

Maybe you are passing an asteriod that is not initialised properly, or the pointer is just junk.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Cash   USA  (626 posts)  Bio
Date Reply #9 on Wed 31 Mar 2004 11:31 PM (UTC)
Message
Actual information is being written into it. I'll go check my asteroid creation functions again and see whats up.

~Nick Cash
http://www.nick-cash.com
Top

Posted by Nick Cash   USA  (626 posts)  Bio
Date Reply #10 on Thu 01 Apr 2004 03:27 AM (UTC)
Message
Ok, well, I've decided that I was going to put this into a snippet anyways, so here is the code (not the snippet).
http://ew.xidus.net/code/3.0a.c
http://ew.xidus.net/code/asteroids.h

Go ahead and take a look. If you want this added to your mud then feel free to use that or wait till I release a more tested version. I *THINK* that code in the .h file is the stuff I'm using in my mud, however, I'm not 100 percent positive. Let me know what you think, especially you guru's. You can prolly find a whole shit load of stuff thats wrong with it, but I think its pretty good for one of my first projects.

Thanks.

~Nick Cash
http://www.nick-cash.com
Top

Posted by Nick Cash   USA  (626 posts)  Bio
Date Reply #11 on Thu 01 Apr 2004 05:02 AM (UTC)
Message
Actually, I see a few minor things wrong with that code already. I'll go ahead and update it tomorrow, however, that code is still what I'm using (except for a few modifications). I will finish the area variable implementation the right way also.

Lata.

~Nick Cash
http://www.nick-cash.com
Top

Posted by Nick Cash   USA  (626 posts)  Bio
Date Reply #12 on Sun 04 Apr 2004 07:38 PM (UTC)
Message
Ok, got a more up to date version up. Take a look and let me know of anything you see wrong with it.

~Nick Cash
http://www.nick-cash.com
Top

Posted by Greven   Canada  (835 posts)  Bio
Date Reply #13 on Sun 04 Apr 2004 08:15 PM (UTC)

Amended on Mon 05 Apr 2004 07:09 AM (UTC) by Greven

Message
Quick run through of the code, and I see a few things. You used fread_string_nohash on filename, but initialized it with STRALLOC. Not a huge things, but its there. Also, this:
sprintf (aName, fread_string(fp));
Is a small memory leak.

Also, double check what the asteroid list looks like, as opposed to the individual asteroid files. Looks like you might have a bad asteroid linked into the list.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
Top

Posted by Nick Cash   USA  (626 posts)  Bio
Date Reply #14 on Mon 05 Apr 2004 06:14 AM (UTC)
Message
Ok, I think I got all that fixed. Not sure if aName = fread_string(fp); is a suitable memory leak fix, but I'm sure you'll let me know. Anyways, I have since cleared the asteroid. I'll go make some asteroids and let you all know how it turns out.

~Nick Cash
http://www.nick-cash.com
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.


113,017 views.

This is page 1, subject is 4 pages long: 1 2  3  4  [Next page]

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.