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, Yahoo!, Sogou

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 » Codebases » AFKMud Support & Development » recall mod
Forum Rules | Mark all | Recent Posts

recall mod
< Newer Topic :: Older Topic > fun with pointers

Pages:<< prev 1 next >>
Post is unread #1 Jan 26, 2004, 6:12 pm
Go to the top of the page
Go to the bottom of the page

cynshard

GroupMembers
Posts95
JoinedNov 19, 2003

I've modified the standard area files to include a recall vnum. This will allow zones to have their own recall points. Useful for cities or whatever. Anyhow, I'm setting the recall vnums to the player whenever the player moves. I wrote the following functions to do this.:
/* Sets recall -- Cynshard */void set_recall( CHAR_DATA *ch, int value ){	ch->pcdata->alsherok = value;	/* ch->pcdata->eletar   = value;    ch->pcdata->alatia   = value; */}/* Returns TRUE if the recall value is different -- Cynshard */bool check_recall( CHAR_DATA *ch, int value ){	if( ch->pcdata->alsherok != value && value != 0 )  return TRUE;	else  return FALSE;}

I'm only using the alsherok continent at the moment.

Anyhow, these two functions are called like this:
In build.c: at the end of each *_goto function
/* Sets recall -- Cynshard */	if( check_recall(ch, location->area->recall) )  set_recall( ch, location->area->recall );

In act_move.c: at the end of the move_char function
/* Set the recall room if necessary -- Cynshard */	if( check_recall(ch, ch->in_room->area->recall) )  set_recall( ch, ch->in_room->area->recall );


If i comment out the function calls in act_move.c the entire mud compiles and runs fine, and the recall room gets set properly if you use any of the goto functions in the game. But if I include the calls in act_move.c the mud compiles fine, but i get a segmentaion fault when i run the executable. I'm quite stumped.

Edit::
If i move the function call to one of the do_direction functions i get no segmentation fault and it works like I want. I suppose the calls are in the wrong place in the move_char function?
       
Post is unread #2 Jan 27, 2004, 1:59 pm
Go to the top of the page
Go to the bottom of the page

Quixadhal
Conjurer
GroupMembers
Posts398
JoinedMar 8, 2005

It's been awhile since I looked at that part of the code... but I suspect that the place you had it in move_char() may be after the character is removed from their original room, and before they are placed into their destination room? If so, in_room will (*should*) be NULL.

One of the annoyances of C pointers is that if you don't have solid, trustworthy, code, you have to do lots of checks to ensure that pointers remain valid.

IE:
 if( check_recall(ch, ch->in_room->area->recall) ) set_recall( ch, ch->in_room->area->recall );


becomes

if(ch && ch->in_room && ch->in_room->area && ch->in_room->area->recall && check_recall(ch, ch->in_room->area->recall))  set_recall(ch, ch->in_room->area->recall);


obviously, you can also put all those checks at the top of check_recall() so it returns false (which would be the proper way to do it).

If you're feeling like pain, you could even break it into seperate checks and make them all like
if(!ch) {  bug("NULL ch!";);  return FALSE;} else if(!ch->in_room) {....


Ugly, no?
       
Post is unread #3 Jan 30, 2004, 10:18 pm
Go to the top of the page
Go to the bottom of the page

cynshard

GroupMembers
Posts95
JoinedNov 19, 2003

Hi, back again. I'm still working on this. I rewrote my check_recall function to check for null pointers and I'm not getting any further. I've even made a few redundant checks. Here is what I did.

Here is the function call...
In move_char:
	if( !ch )  bug( "%s", "Null Char Before check_recall" );	else  check_recall( ch, 0 );

NOTE: the 0 in the function call is to ensure that SOME value is being passed to the function for now. It'll be replaced when i manage to get the mud to run.
and here is the actual check_recall function:
bool check_recall( CHAR_DATA *ch, int value ){	// Making more checks to find my problems	if(!ch)	{  bug( "%s", "Check_recall: NULL ch!";);  return FALSE;	} else if(!ch->in_room) {  bug( "%s", "Check_recall: NULL ch->in_room!";);  return FALSE;	} else if(!ch->in_room->area) {  bug( "%s", "Check_recall: NULL ch->in_room->area!";);  return FALSE;	} else if(!ch->in_room->area->recall) {  bug( "%s", "Check_recall: NULL ch->in_room->area->recall!";);  return FALSE;	} else if( ch->pcdata->alsherok && ch->pcdata->alsherok != ch->in_room->area->recall && ch->in_room->area->recall != 0 ) {  return TRUE;	} else  return FALSE;}

In addition to these changes I created another function, test_func, mostly from desparation .
Here is the call in move_char:
test_func( ch, 0 );

And here is the actual function:
void test_func( CHAR_DATA *ch, int value ){	if(ch)  bug( "%s", "test_func: I hit this far..." );	else  bug( "%s", "test_func: NULL ch!" );}

NOTE: this function is called 1 line below where I'm currently calling check_recall.
When I comment out the check_recall function and leave the test_func in the mud compiles and runs normally, and spams the log with the bug message, as is expected.

At this point I'm 22.73% Frustrated
Cynshard
       
Post is unread #4 Jan 30, 2004, 10:45 pm
Go to the top of the page
Go to the bottom of the page

cynshard

GroupMembers
Posts95
JoinedNov 19, 2003

Aha.

I discoved that I wasn't checking to see if ch->pcdata was a valid pointer. I suppose that since move_char is used for more than just PCs it was dying when it hits ch->pcdata->alsherok. Seems to be working now.

Thanks for the excellent tip on checking all the pointers.

Cynshard
       
Post is unread #5 Jan 31, 2004, 5:12 am
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

Ah yes. Good ol ch->pcdata. Keep forgetting to consider that. I was looking up and down, left and right, for a reason in move_char that it would crash. Sadly, even though I've made this mistake countless times, I never considered pcdata.
       
Pages:<< prev 1 next >>