Crash caused by new config/get_eq_char code

Posted by Dralnu on Mon 20 Jun 2005 02:23 PM — 14 posts, 34,995 views.

USA #0
I'm not sure what the problem here is, so I'll post the code and let you see for yourself


OBJ_DATA *
get_eq_char (CHAR_DATA * ch, int iWear)
{
	OBJ_DATA *obj, *maxobj = NULL;
	OBJ_DATA *cloak = NULL;
	for (obj = ch->first_carrying; obj; obj = obj->next_content)
		{
			if (obj->wear_loc == WEAR_ABOUT)   checks for cloak in wear_loc WEAR_ABOUT
			cloak = obj;
		}
	for (obj = ch->first_carrying; obj; obj = obj->next_content)
		{
			if (ch->pcdata && IS_SET (ch->pcdata->flags, PLR_CLOAK) && cloak)
			{
				if (obj->wear_loc != WEAR_FEET && obj->wear_loc != WEAR_HEAD && obj->wear_loc != WEAR_HANDS &&obj->wear_loc != WEAR_ABOUT && obj->wear_loc != WEAR_FACE && obj->wear_loc != WEAR_FLOAT && obj->wear_loc != WEAR_SHOULDER)
				continue;
			}
			else if (obj->wear_loc == iWear)
			{
				if (!obj->pIndexData->layers)
				return obj;
				else if (!maxobj || obj->pIndexData->layers > maxobj->pIndexData->layers)
				maxobj = obj;
			}
		}
	return maxobj;
}


I know it is caused by that somehow, or something related to it because it only crashes when you remove an obj, and when I changed to the stock code it worked perfectly fine



Edit #1
Forgot to subscribe, lol
Amended on Mon 20 Jun 2005 02:30 PM by Dralnu
USA #1
Can you show us the gdb results?
USA #2
Had a hard time with gdb, so I didn't get into it since I was fairly sure it was that code. I've changed the code some since then, the only problem I have now is the code working to only show certaint wearlocs.


OBJ_DATA *
get_eq_char (CHAR_DATA * ch, int iWear)
{
	OBJ_DATA *obj, *maxobj = NULL;
	for (obj = ch->first_carrying; obj; obj = obj->next_content)
		{
			if (ch->pcdata && IS_SET (ch->pcdata->flags, PLR_CLOAK) && obj->wear_loc == WEAR_ABOUT)
			{
				if (obj->wear_loc != WEAR_FEET && obj->wear_loc != WEAR_HEAD && obj->wear_loc != WEAR_HANDS && obj->wear_loc != WEAR_ABOUT && obj->wear_loc != WEAR_FACE && obj->wear_loc != WEAR_FLOAT && obj->wear_loc != WEAR_SHOULDER)
					{
						return obj;
						maxobj = obj;
					}
			}
			else if (obj->wear_loc == iWear)
			{
				if (!obj->pIndexData->layers)
					{
						return obj;
					}
				else if (!maxobj || obj->pIndexData->layers > maxobj->pIndexData->layers)
					{
						maxobj = obj;
					}
			}
		}
	return maxobj;
}


That doesn't cause crashes (for some odd reason), but the first if doesn't seem to work entirly right. It should only return feet, hands, about, ect., w/o shoing body and some other wearlocs. If I can get that to work I think I'll be good
USA #3
It's really hard to find out why it crashed without gdb. For all I know, an obj could be null.
USA #4
I'll see if I cann't get gdb to work for me, but at least I got it past the crashing point.
USA #5
What were you having a hard time with? You should just be able to attach gdb to the process, continue, and cause the crash.
USA #6
Some reason it just doesn't seem to like me, but like I said it doesn't crash anymore when you remove equipment like it did with the first posted code. Right now I just need to get the ifcheck to return the right wearlocs instead of showing everything, and I'll be done for the most part, cept maybe for cosmetic changes for send_to_char at times.
USA #7
Like Zeno said, you really should get gdb to work, that'll make debugging a lot simpler; random stabs are never a good idea. :)

As to your specific problem, it's hard to see what is wrong without knowing exactly what you had in mind. You're doing some odd stuff, for instance, after the inner-most if statement, you return maxobj but then assign obj to maxobj. But by returning maxobj, you've already left the function...
USA #8
The return bit was trying to get something to work. As for random stabs, I knew it was that since it only crashed after the change in code and when the code worked. As for what I'm trying to do, is a cloak config to allow players to hide certain wearlocs, such as body, to help them keep their equip somewhat secret as for pk. I hope that helps explain what my goal is...
USA #9
Not really. :-) What is this 'maxobj' business?
USA #10
Rash attempt to get it to work. As is, with PLR_CLOAK on, when you look at someone, it doesn't show any equip on them, which is the problem as of right now

If I set it to return maxobj, think that would work? Or do I need to do something else to get it to work right?
USA #11
You know, there's a bigger problem with this approach. get_eq_char is used for lots of stuff, not just looking at people. If you start messing with it, you might find that your whole game is affected. Namely, that the game will not know if somebody is wearing something if they have a cloak on.

What is the difference between the player flag 'cloak' and having something about you?
USA #12
restricting what people see. Its kind of like pulling your cloak around you to hide what you are wearing...
USA #13
That's not what I meant. :) Your if statement checks for those two things:
if (ch->pcdata && IS_SET (ch->pcdata->flags, PLR_CLOAK) && obj->wear_loc == WEAR_ABOUT)
Is that what you want to do?

Furthermore, if you've established that obj is a wear_about item, how could it possibly be any of the other wearlocs you're checking for?

Looking over your first solution again, it actually looks like it's much closer to what you want to do. The second solution is simply wrong.

As to why your code is crashing, I'm almost certain that it's because you messed with the wrong function. As I said, get_eq_char is a function that the game uses to determine a player's equipment. What you're trying to do is prevent a player from seeing somebody else's equipment. Those are two very different things; by changing get_eq_char you probably are breaking a huge number of things.