Welcome to the Builder Academy

Question Fight.c crash

More
19 Dec 2016 22:09 #6420 by WhiskyTest
Replied by WhiskyTest on topic Fight.c crash
Inconsistent crashes are a nightmare to track down sometimes!

Just to give you some more stuff to think about - here is an example when NULL is specifically sent to die().

In ACMD(do_quit)
line 52 (in stock code) we see:
Code:
else if (GET_POS(ch) < POS_STUNNED) { send_to_char(ch, "You die before your time...\r\n"); die(ch, NULL); } else {
So if a player is incapacitated and they type quit - NULL gets sent as the killer. That might explain why in the third screenshot we see argument = "quit", then the reference to the faulting function die().

That is why when we expand on code functions it is important to look for all the places the function gets used. Adding "dummy checks" is never a bad idea too, you'll often see them at the start of functions like checking that *ch isn't an NPC or that *arg isn't empty etc..

Please Log in or Create an account to join the conversation.

More
19 Dec 2016 23:01 #6421 by JTP
Replied by JTP on topic Fight.c crash
how come adding if (killer && !IS_NPC(killer)) { will fix a NULL ?

Instead of the old
if (!IS_NPC(killer))

Please Log in or Create an account to join the conversation.

More
19 Dec 2016 23:04 #6422 by JTP
Replied by JTP on topic Fight.c crash
Or maybe it actually does, its midnight now haha

Please Log in or Create an account to join the conversation.

More
19 Dec 2016 23:10 #6423 by WhiskyTest
Replied by WhiskyTest on topic Fight.c crash
Haha it's lunchtime here :D

If you just have if (!IS_NPC(killer)) and killer is NULL then the Mud tries to check whether NULL is an NPC which will do strange things or crash.

If you say if (killer && !IS_NPC(killer)) then the Mud checks if killer is NULL first - if it is NULL then it doesn't carry on with the stuff after &&, thereby avoiding the crash.

That's my take on it - Rumble or Thomas might be able to clarify further as they are real coders :)

Please Log in or Create an account to join the conversation.

More
20 Dec 2016 07:51 - 20 Dec 2016 07:52 #6424 by JTP
Replied by JTP on topic Fight.c crash
Hmm guess that wasnt enough, still refering to the same line in fight.c, but updated with the killer &&
Attachments:
Last edit: 20 Dec 2016 07:52 by JTP.

Please Log in or Create an account to join the conversation.

More
20 Dec 2016 18:47 #6425 by thomas
Replied by thomas on topic Fight.c crash
Now THAT is weird. WhiskyTest is right, the "killer &&" should have removed this bug.

Are you sure you've compiled after editing the code?

Please Log in or Create an account to join the conversation.

Time to create page: 0.240 seconds