Author Topic: eventMove() in an add_action() seems to cause nasty results.  (Read 4652 times)

Offline lokkje

  • Acquaintance
  • *
  • Posts: 4
    • View Profile
on my DS 2.7 MUD, run on Ubuntu 8.04, the following function causes a segmentation fault, forcing the MUD to rash and reboot:

Code: [Select]
int crypt(){
if(this_player()->GetClass() == "necromancer") {
this_player()->eventMove("/domains/Juna/room/catacombs/start");
}
else if(this_player()->GetClass() != "necromancer") {
this_player()->eventPrint("You try to enter one of the tombs, but a strange force prevents you from entering.\nYou look down in horror as your legs begin to rot!");
this_player()->eventReceiveDamage("necrosis", DEATH, (this_player()->GetMaxHealthPoints() / 25), 0);
}
}

Oddly enough, though, once successfully rebooted and logged in, i find myself in the room intended.

Here are the entrys from both /log/crashes and from the server window:

Quote
---
Chaos Realm crashed Wed May 14 18:07:55 2008 with error Segmentation fault.

0:"get_stack".OBJ(/secure/sefun/sefun)."get_stack"
1:"crash".OBJ(/secure/daemon/master)."crash"
({ })
---

Quote
******** FATAL ERROR: Segmentation fault
FluffOS driver attempting to exit gracefully.
crash() in master called successfully.  Aborting.
Aborted
using config file: ./mudos.cfg
Initializing internal tables....

Any thoughts?
« Last Edit: May 14, 2008, 06:32:02 pm by lokkje »

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1024
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: eventMove() in an add_action() seems to cause nasty results.
« Reply #1 on: May 14, 2008, 06:49:44 pm »
Neat.

This is something I'd like to get Wodan's input on...I'm not sure why
it's a crasher. I was able to reproduce the problem with the following code:

Code: [Select]
#include <lib.h>

inherit LIB_ITEM;

int crypt(){
        if(this_player()->GetClass() == "explorer") {
                this_player()->eventMove("/domains/campus/room/start");
        }
        else if(this_player()->GetClass() != "explorer") {
                this_player()->eventPrint("You try to enter one of the tombs, but a strange force prevents you from entering.\nYou look down in horror as your legs begin to rot!");
                this_player()->eventReceiveDamage("necrosis", 1, (this_player()->GetMaxHealthPoints() / 25), 0);
        }
//return 1;
}

static void create() {
    item::create();
    SetKeyName("key");
    SetId( ({ "key", "sample key" }) );
    SetAdjectives( ({ "simple","sample" }) );
    SetShort("a sample key");
    SetLong("It is a simple sample key with no markings.");
    SetMass(50);
    SetBaseCost(1);
    SetDisableChance(100);
}
void init(){
::init();
add_action("crypt","crypt");
}


Quote
Dead Souls Alpha /realms/cratylus/area/obj >
crypt
Reality implosion!!!  Everyone duck!!!
You are being forced to quit.
Please come back another time!
You remove a suit of powered scout armor.
You remove wire-rimmed glasses.
% Connection lost

However, when I uncomment the return line
Code: [Select]
//return 1;
The crash goes away.

-Crat

Offline wodan

  • BFF
  • ***
  • Posts: 434
  • Drink and code, you know you want to!
    • View Profile
Re: eventMove() in an add_action() seems to cause nasty results.
« Reply #2 on: May 15, 2008, 06:49:44 am »
can't look at the driver source at the moment, but i'm pretty sure there's a crypt() efun, maybe it gets confused with that somehow, do you crash when you use a different function name as well?

Also, if you say a function returns something, return something!

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1024
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: eventMove() in an add_action() seems to cause nasty results.
« Reply #3 on: May 15, 2008, 07:48:03 am »
Quote
i'm pretty sure there's a crypt() efun

That was the first thing that struck me...but the
same problem occurs if you name the fun to
something non-conflicting.

-Crat

Offline daelaskai

  • BFF
  • ***
  • Posts: 174
    • View Profile
Re: eventMove() in an add_action() seems to cause nasty results.
« Reply #4 on: May 15, 2008, 09:55:25 am »
Okay, I don't have a DS mud running at the moment on this PC, but this is
just my input and I don't know if it relates to the crash or not.

I would think that the function itself could be rewritten a bit.
Why is there a second if() statement?

Code: [Select]
int crypt(){
if(this_player()->GetClass() == "necromancer") {
this_player()->eventMove("/domains/Juna/room/catacombs/start");
}
else if(this_player()->GetClass() != "necromancer") {
this_player()->eventPrint("You try to enter one of the tombs, but a strange force prevents you from entering.\nYou look down in horror as your legs begin to rot!");
this_player()->eventReceiveDamage("necrosis", DEATH, (this_player()->GetMaxHealthPoints() / 25), 0);
}
}

I think this could be changed to this:

Code: [Select]
int crypt()
{
if(this_player()->GetClass() == "necromancer")
        {
this_player()->eventMove("/domains/Juna/room/catacombs/start");
}
else
        {
this_player()->eventPrint("You try to enter one of the tombs, but a strange force prevents you from entering.\nYou look down in horror as your legs begin to rot!");
this_player()->eventReceiveDamage("necrosis", DEATH, (this_player()->GetMaxHealthPoints() / 25), 0);
}
        return 1;
}

Again, this just caught my eye when I looked at the function.

Daelas

Offline daelaskai

  • BFF
  • ***
  • Posts: 174
    • View Profile
Re: eventMove() in an add_action() seems to cause nasty results.
« Reply #5 on: May 15, 2008, 10:17:48 am »
Okay, I booted up DS 2.6.2 (after confirming that the original code crashed the mud)
and I got the same behavior you are describing.  It crashed as soon as I typed
the add_action().  I made the initial modification (without the second if() ) I proposed
and tested again and only got the "undefined DEATH" error, no crash.  So far
so good, I thought... I removed the eventReceiveDamage() coe and tested this function:

Code: [Select]
#include <lib.h>

inherit LIB_ITEM;

int docrypt()
{
if(this_player()->GetClass() == "necromancer")
        {
                this_player()->eventMove("/domains/Juna/room/catacombs/start");
}
else
        {
this_player()->eventPrint("You try to enter one of the tombs, but a strange force prevents you from entering.\nYou look down in horror as your legs begin to rot!");
}
        return 1;
}

static void create()
{
    item::create();
    SetKeyName("key");
    SetId( ({ "key", "sample key" }) );
    SetAdjectives( ({ "simple","sample" }) );
    SetShort("a sample key");
    SetLong("It is a simple sample key with no markings.");
    SetMass(50);
    SetBaseCost(1);
    SetDisableChance(100);
}

void init()
{
::init();
add_action("docrypt","docrypt");
}

No problems occurred from this code at all.  I hope this helps people.
I'm not sure if this addresses the problem or not since I'm not sure
where the bug was, in eventReceiveDamage(), in eventMove() or in
the second "else if()" in the code.

Daelas