Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, 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.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ Pointers to Pointers Maybe(?) Help.
Pointers to Pointers Maybe(?) Help.
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1 2
Posted by
| Tsurin
(8 posts) Bio
|
Date
| Wed 15 Sep 2004 09:47 PM (UTC) |
Message
| Hey everyone...
This is a hard task for me for some reason cuz i can never get this to work. I need to have a structure i've made go off of the character data, similar to the pcdata...
Typedef struct mystruct MYSTRUCT;
struct mystruct
{
int test;
};
and in struct char_data i have MYSTRUCT *mystruct;
I have in another function this...
ch->mystruct->test = 10;
ch_printf( ch, "%d/n/r", ch->mystruct->test );
everytime i use the function, the mud crashes...its smaug...and the line of problem is ch->mystruct->test = 10;
how can I get this ch->mystruct->test to work? | Top |
|
Posted by
| Nick Cash
USA (626 posts) Bio
|
Date
| Reply #1 on Wed 15 Sep 2004 10:18 PM (UTC) |
Message
| This is similar to the pcdata struct. Go find the call to CREATE( pcdata, PC_DATA, 1 ); or similar. Below it, do this:
CREATE( ch->mystruct, MYSTRUCT, 1 );
The reason its crashing is because its a null pointer. |
~Nick Cash
http://www.nick-cash.com | Top |
|
Posted by
| Tsurin
(8 posts) Bio
|
Date
| Reply #2 on Thu 16 Sep 2004 01:49 AM (UTC) Amended on Thu 16 Sep 2004 02:50 AM (UTC) by Tsurin
|
Message
| Alright I tried to work with this by making my powerlevel system into that form... First off these are the errors.
#0 0x080f2bde in get_plvl_maxx (ch=0x0) at plvl.c:75
75 return URANGE( PWR_MIN, (ch->energy->capacity), PWR_MAX );
(gdb) bt
#0 0x080f2bde in get_plvl_maxx (ch=0x0) at plvl.c:75
#1 0x080f2c32 in get_plvl_curr (ch=0x83a4508) at plvl.c:87
#2 0x08123f33 in char_update () at update.c:943
#3 0x08125c91 in update_handler () at update.c:2058
#4 0x08096d66 in game_loop () at comm.c:722
#5 0x08096655 in main (argc=2, argv=0xbffff874) at comm.c:329
#6 0x40063d06 in __libc_start_main () from /lib/libc.so.6
(gdb)
the ch->energy is made from the CREATE command. All i get is a segmentation fault.
Everything is exactly the way as if i did it with mystruct. The only thing different is the categories. Help?
| Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #3 on Thu 16 Sep 2004 04:40 AM (UTC) Amended on Thu 16 Sep 2004 04:57 AM (UTC) by David Haley
|
Message
| #0 0x080f2bde in get_plvl_maxx (ch=0x0) at plvl.c:75
75 return URANGE( PWR_MIN, (ch->energy->capacity), PWR_MAX );
(gdb) bt
#0 0x080f2bde in get_plvl_maxx (ch=0x0) at plvl.c:75
#1 0x080f2c32 in get_plvl_curr (ch=0x83a4508) at plvl.c:87
Somehow, you managed to use a null character. The problem isn't in ch->energy, it's in ch itself.
(amended to fix formatting) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Nick Cash
USA (626 posts) Bio
|
Date
| Reply #4 on Thu 16 Sep 2004 04:53 AM (UTC) |
Message
|
Quote:
#0 0x080f2bde in get_plvl_maxx (ch=0x0) at plvl.c:75
#1 0x080f2c32 in get_plvl_curr (ch=0x83a4508) at plvl.c:87
Looks to me like you should inspect get_plvl_curr and see why it didnt pass ch along, or why it made ch NULL. Paste the function here and we could probably help. |
~Nick Cash
http://www.nick-cash.com | Top |
|
Posted by
| Tsurin
(8 posts) Bio
|
Date
| Reply #5 on Thu 16 Sep 2004 10:53 AM (UTC) |
Message
| //THE CURRENT STORED POWER OF A CHARACTER//
long get_plvl_curr( CHAR_DATA *ch )
{
return URANGE( 0, ((get_plvl_maxx(ch)) - (ch->energy->depleted)), (get_plvl_maxx(ch)) );
}
//THE TOTAL POWERLEVEL OF A CHARACTER//
long get_plvl_maxx( CHAR_DATA *ch )
{
return URANGE( PWR_MIN, (ch->energy->capacity), PWR_MAX );
}
those are the two functions that are shown in that statement... | Top |
|
Posted by
| Tsurin
(8 posts) Bio
|
Date
| Reply #6 on Thu 16 Sep 2004 05:59 PM (UTC) |
Message
| if the problem is in ch itself, what do you suggest doing so that i can pinpoint it out? | Top |
|
Posted by
| Tsurin
(8 posts) Bio
|
Date
| Reply #7 on Thu 16 Sep 2004 08:57 PM (UTC) |
Message
| Ok to try and make things more clearer, I'm going to paste my code and put where things are called.
In Mud.h
after structure types, with the rest of them, i put...
typedef struct energy_data ENERGY;
in char_data and in mob_index_data i put...
ENERGY * energy;
somewhat space below I have the structure itself...
struct energy_data
{
long capacity;
long generate;
long prepared;
long depleted;
};
in plvl.c i have these functions....
//THE TOTAL POWERLEVEL OF A CHARACTER//
long get_plvl_maxx( CHAR_DATA *ch )
{
return URANGE( PWR_MIN, (ch->energy->capacity), PWR_MAX );
}
//THE AVAILABLE POWER OF A CHARACTER//
long get_plvl_av( CHAR_DATA *ch )
{
return URANGE( 0, ch->energy->prepared, get_plvl_maxx(ch) );
}
//THE CURRENT STORED POWER OF A CHARACTER//
long get_plvl_curr( CHAR_DATA *ch )
{
return URANGE( 0, ((get_plvl_maxx(ch)) - (ch->energy->depleted)), (get_plvl_maxx(ch)) );
}
//THE CURRENT POWER UP//
long get_plvl_up( CHAR_DATA *ch )
{
return URANGE( 0, (ch->energy->generate), PWR_MAX );
}
in comm.c as a part of the prompt and fprompt i have..,
case 'P':
stat = get_plvl_maxx(ch); /*Max Power Level*/
break;
case 'p':
stat = get_plvl_curr(ch); /*Current Power Level*/
break;
case 'E':
stat = get_plvl_up(ch); /* Power Up */
break;
case 'e':
stat = get_plvl_av(ch); /* Energy */
break;
in update.c i as a part of the regenerate section, i put..
if ( get_plvl_curr(ch) < get_plvl_maxx(ch) )
ch->energy->depleted -= plvl_curr_gain(ch);
in save.c, to do the create thingy, i have...
fprintf( fp, "Power_Level %ld %ld %ld\n",
ch->energy->capacity, ch->energy->generate, ch->energy->depleted );
and
if ( !strcmp( word, "Power_Level" ) )
{
CREATE( ch->energy, ENERGY, 1 );
ch->energy->capacity = fread_number( fp );
ch->energy->generate = fread_number( fp );
ch->energy->depleted = fread_number( fp );
fMatch = TRUE;
break;
}
thats everything that the segfault involves...here is the segfault again
#0 0x080f2bde in get_plvl_maxx (ch=0x0) at plvl.c:75
75 return URANGE( PWR_MIN, (ch->energy->capacity), PWR_MAX );
(gdb) bt
#0 0x080f2bde in get_plvl_maxx (ch=0x0) at plvl.c:75
#1 0x080f2c4f in get_plvl_curr (ch=0x83a4508) at plvl.c:87
#2 0x08123f2b in char_update () at update.c:944
#3 0x08125c89 in update_handler () at update.c:2061
#4 0x08096d66 in game_loop () at comm.c:722
#5 0x08096655 in main (argc=2, argv=0xbfffeb64) at comm.c:329
#6 0x40063d06 in __libc_start_main () from /lib/libc.so.6
It does this right on the startup of the mud. Log is fine. Before i switched the system to its own structure, it used to be ch->generate, ch->capacity, and so on so forth. It worked fine then. After I switched and followed the examples given to me, it gives me that segfault. My theory is that its in the energy->portion but i do not understand how considering that I've added the CREATE ( ch->energy, ENERGY, 1 ); into the save.c file with the rest of the stats...Please help me... | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #8 on Thu 16 Sep 2004 09:16 PM (UTC) |
Message
| The problem is not in the ch->energy structure, according to gdb ch itself is null.
I would suggest doing a full recompile and testing again:
make clean
make
I'm not seeing anything wrong with the functions, but a full recompile might help. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Zeno
USA (2,871 posts) Bio
|
Date
| Reply #9 on Thu 16 Sep 2004 09:25 PM (UTC) |
Message
| He's tried that multiple times, I've talked to him over AIM. |
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | Top |
|
Posted by
| Tsurin
(8 posts) Bio
|
Date
| Reply #10 on Thu 16 Sep 2004 09:27 PM (UTC) |
Message
| and still a no go...the same segfault. | Top |
|
Posted by
| Nick Cash
USA (626 posts) Bio
|
Date
| Reply #11 on Fri 17 Sep 2004 01:16 AM (UTC) |
Message
| It seems like is should work. Perhaps switching back to how you had it before would be best. |
~Nick Cash
http://www.nick-cash.com | Top |
|
Posted by
| Tsurin
(8 posts) Bio
|
Date
| Reply #12 on Fri 17 Sep 2004 01:33 AM (UTC) |
Message
| but that sparks another question because i'm definately going to need this with the next thing i code. Is this problem gonna keep showing up? If so, i'd have to find out how to fix it and fix it now. | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #13 on Fri 17 Sep 2004 01:42 AM (UTC) |
Message
| One problem you might be having is that the ENERGY structure is [b]only[/b] created [b]if[/b] the load function finds an entry in the pfile.
This doesn't explain the null ch problem, but it's still something to fix.
You want to create the energy structure like you were told at the same place the PCDATA structure is created, not in the part where you read the data from the file. :) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Samson
USA (683 posts) Bio
|
Date
| Reply #14 on Fri 17 Sep 2004 12:36 PM (UTC) |
Message
| Mystery bugs like this are best found and fixed by tools other than GDB. It's possible the null ch is coming from something unrelated and this code is just what finally brought the problem to light. Time to bust out Valgrind and have a go if possible. Generally Valgrind will give you a much more detailed breakdown of how something like this happens.
One possibility is that not creating the ch->energy struct if there isn't a pfile entry is that it COULD be causing stack corruption which has been known to lead to bad GDB traces. It might have caused ch to point to NULL data somehow. Stranger things have happened. | 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.
43,785 views.
This is page 1, subject is 2 pages long: 1 2
It is now over 60 days since the last post. This thread is closed.
Refresh page
top