Wintermute Engine Forum

Wintermute Engine => Bug reports => Fixed => Topic started by: Eshaktaar on February 25, 2008, 01:14:50 AM

Title: Crash when NPC is reset when walking
Post by: Eshaktaar on February 25, 2008, 01:14:50 AM
Hello, first post here!

I'm currently experimenting with WME to get a feel for what it can do, and I seem to have hit a bug:

I have an NPC that walks around the scene (inside an endless loop). When the player clicks on the NPC, I want the NPC to stop what she's doing until the player actor has reached her position. After a short talk, the NPC will then resume her walk. To stop the NPC, I call her Reset() function. Then the player actor says a line, and when the NPC is supposed to answer, the game shuts down.

I could recreate the bug in a simpler example here (NPC's script):

Code: [Select]
#include "scripts\base.inc"

this.GoTo(400, 470);

////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
this.Reset();
actor.GoTo(this.X, this.Y);
this.GoTo(400, 470);
}

When I click on the NPC she stops and waits for the player actor to reach her position. But when the NPC is supposed to continue walking, the game crashes. Note that this only happens if I click on the NPC while she is still walking. If she stands still, the code works.
Title: Re: Crash when NPC is reset when walking
Post by: metamorphium on February 25, 2008, 08:39:53 AM
could you please post all relevant scripts including the endless loop?
Title: Re: Crash when NPC is reset when walking
Post by: Eshaktaar on February 25, 2008, 12:51:48 PM
Certainly, the endless loop is also in the NPC's script:

Code: [Select]
#include "scripts\base.inc"

walkAround();

////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
this.Reset();
actor.GoTo(this.X, this.Y);
this.GoTo(200, 470); // crash happens here
}

////////////////////////////////////////////////////////////////////////////////
on "Talk"
{
this.Reset();
actor.GoTo(this.X, this.Y);
actor.Talk("Hey there!"); // crash happens before this line appears on screen
this.Talk("Go away!");
walkAround();
}

// LOOP
function walkAround()
{
while (true)
{
this.GoTo(200, 470);
Sleep(5000);
this.GoTo(600, 470);
Sleep(5000);
}
}

My first description was inaccurate, I noticed: In the Talk event the crash happens before the player actor can say "Hey there!", right after "actor.GoTo(this.X, this.Y);". If I remove the line "actor.GoTo(this.X, this.Y);" in the Talk event, the player actor can say her line, and then the crash occurs.

If I comment out "this.Reset();" and "walkAround();" in the Talk event, no crash happens. In this case, however, I can talk to the NPC only once, and then she becomes "inactive" and talking to her or left-clicking on her does nothing (even though her caption still appears when the mouse is over her).
Title: Re: Crash when NPC is reset when walking
Post by: Mnemonic on February 25, 2008, 12:58:32 PM
Thanks, Eshaktaar. I'll see if I can reproduce the crash.
Title: Re: Crash when NPC is reset when walking
Post by: Eshaktaar on March 04, 2008, 09:10:34 AM
Thanks. I could reproduce the crash on two different machines (one with XP and one with Vista).
Title: Re: Crash when NPC is reset when walking
Post by: Mnemonic on March 15, 2008, 01:29:00 PM
Ok, I removed the crash, but this script won't work as you expect it anyway. Calling Reset() does actually terminate all the scripts currently waiting for the object being reset. So in this case, calling Reset() while the NPC is walking will terminate the whole script (the script is waiting for the actor to stop walking). You might want to redesign the script, to call the walking in a separate "thread". See this script (http://wiki.dead-code.org/wakka.php?wakka=IdleActorScript) for an inspiration. Notice the "idle" event, which can be safely terminated, while the rest of the script continues to work.
Title: Re: Crash when NPC is reset when walking
Post by: Eshaktaar on March 20, 2008, 02:47:34 PM
Cool, thank you. I'll try to implement the idle behaviour according to the Wiki example.