this.shipDied firing repeatedly in shipScript....1.76

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

this.shipDied firing repeatedly in shipScript....1.76

Post by Capt. Murphy »

What's the expected behaviour of event handler this.shipDied in shipScript? Shouldn't it only fire once when it's the script's this.ship that dies?

the code looks like this...

Code: Select all

this.shipDied = function()
{
    worldScripts["nullgate_main.js"].removeNullgateLocation(galaxyNumber,system.ID,this.ship.primaryRole,this.nullgateState); // remove entry from array
     worldScripts["nullgate_main.js"].addNullgateLocation(galaxyNumber,system.ID,"no-nullgate","destroyed"); // add destroyed entry from array
    this.ship.switchAI("nullgate_detonateAI.plist"); // this will result in an energy cascade...
    this.stopTimer();
}
the AI called is very simply

Code: Select all

{
	GLOBAL =
	{
		ENTER = (becomeEnergyBlast);
	};	
}
the worldScript functions called produce log entries which indicate that this.shipDied is firing repeatedly every few milliseconds, whilst there is eventually ( well after about 7 milliseconds :wink: ) an AI stack overflow. Is it to do with the entity becoming an energy cascade?
06:31:48.500 [nullgate_main.js]: this.removeNullgateLocation called with parameters galaxy:0, system:7, roleString:working-nullgate, stateString:angry
06:31:48.500 [nullgate_main.js]: Nullgate location record: [0,7,working-nullgate,angry] cannot be removed as does not exist.
06:31:48.500 [nullgate_main.js]: this.addNullgateLocation called with parameters galaxy:0, system:7, roleString:no-nullgate, stateString:destroyed
06:31:48.500 [nullgate_main.js]: One nullgate location record updated: [0,7,no-nullgate,destroyed] added to array.
06:31:48.500 [nullgate_main.js]: this.removeNullgateLocation called with parameters galaxy:0, system:7, roleString:working-nullgate, stateString:angry
06:31:48.500 [nullgate_main.js]: Nullgate location record: [0,7,working-nullgate,angry] cannot be removed as does not exist.
06:31:48.500 [nullgate_main.js]: this.addNullgateLocation called with parameters galaxy:0, system:7, roleString:no-nullgate, stateString:destroyed
06:31:48.500 [nullgate_main.js]: One nullgate location record updated: [0,7,no-nullgate,destroyed] added to array.
06:31:48.501 [ai.error.stackOverflow]: ***** ERROR: AI stack overflow for <ShipEntity 0xc386120>{"Null Gate"} in nullgate_detonateAI.plist: GLOBAL -- stack:

06:31:48.501 [ai.error.stackOverflow.dump]: 31: NullGateAI.plist: IDLE
06:31:48.501 [ai.error.stackOverflow.dump]: 30: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 29: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 28: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 27: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 26: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 25: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 24: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 23: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 22: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 21: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 20: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 19: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 18: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 17: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 16: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 15: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 14: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 13: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 12: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 11: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 10: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 9: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 8: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 7: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 6: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 5: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 4: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 3: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 2: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 1: nullgate_detonateAI.plist: GLOBAL
06:31:48.501 [ai.error.stackOverflow.dump]: 0: nullgate_detonateAI.plist: GLOBAL
06:31:48.503 [script.javaScript.exception.ooliteDefinedError]: ***** JavaScript exception (nullgate_shipscript.js 0.9 - for Oolite 1.75 and later): Error: Native exception: AI stack overflow for <ShipEntity 0xc386120>{"Null Gate" position: (-490424, -371947, 484524) scanClass: CLASS_STATION status: STATUS_DEAD}
06:31:48.503 [script.javaScript.stackTrace]: 0 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.503 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.503 [script.javaScript.stackTrace]: 1 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.503 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.503 [script.javaScript.stackTrace]: 2 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.503 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.503 [script.javaScript.stackTrace]: 3 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.503 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.503 [script.javaScript.stackTrace]: 4 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.503 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.503 [script.javaScript.stackTrace]: 5 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.503 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.503 [script.javaScript.stackTrace]: 6 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.503 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.503 [script.javaScript.stackTrace]: 7 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.503 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.503 [script.javaScript.stackTrace]: 8 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.503 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.503 [script.javaScript.stackTrace]: 9 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.503 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.504 [script.javaScript.stackTrace]: 10 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.504 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.504 [script.javaScript.stackTrace]: 11 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.504 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.504 [script.javaScript.stackTrace]: 12 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.504 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.504 [script.javaScript.stackTrace]: 13 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.504 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.504 [script.javaScript.stackTrace]: 14 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.504 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.504 [script.javaScript.stackTrace]: 15 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.504 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.504 [script.javaScript.stackTrace]: 16 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.504 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.504 [script.javaScript.stackTrace]: 17 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.504 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.504 [script.javaScript.stackTrace]: 18 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.504 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.504 [script.javaScript.stackTrace]: 19 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.504 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.504 [script.javaScript.stackTrace]: 20 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.504 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.504 [script.javaScript.stackTrace]: 21 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.504 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.504 [script.javaScript.stackTrace]: 22 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.504 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.504 [script.javaScript.stackTrace]: 23 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.504 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.504 [script.javaScript.stackTrace]: 24 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.504 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.504 [script.javaScript.stackTrace]: 25 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.504 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.504 [script.javaScript.stackTrace]: 26 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.504 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.505 [script.javaScript.stackTrace]: 27 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.505 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.505 [script.javaScript.stackTrace]: 28 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.505 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.505 [script.javaScript.stackTrace]: 29 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.505 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.505 [script.javaScript.stackTrace]: 30 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.505 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]
06:31:48.505 [script.javaScript.stackTrace]: 31 (nullgate_shipscript.js:161) <anonymous function>
06:31:48.505 [script.javaScript.stackTrace]: this: [Script "nullgate_shipscript.js" version 0.9 - for Oolite 1.75 and later]

I can work around easily by deleting this.shipDied after it has run once, but this seems a bit buggy....
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: this.shipDied firing repeatedly in shipScript....1.76

Post by Eric Walch »

Somehow expected behaviour. "becomeEnergyBlast" triggers the shipDied. And when you kill yourself again when already dead, you die again :roll:

As you have all the test-code at hand, you could modify the source to see if it helps. In ShipEntity.m around line 5827 in noteKilledBy: change:

Code: Select all

- (void) noteKilledBy:(Entity *)whom damageType:(OOShipDamageType)type
{
	[PLAYER setScriptTarget:self];
into

Code: Select all

- (void) noteKilledBy:(Entity *)whom damageType:(OOShipDamageType)type
{
	if ([self status] == STATUS_DEAD)  return;
	
	[PLAYER setScriptTarget:self];
........
Thinking it over, it is a bit complex. The ships status is only temporary set to DEAD so its dead when the handler fires. After that is becomes the old status again and the ship only really dies later in the code. On the other hand, when calling it recursive, a second time, the second call does sees it as original DEAD, even when the status will be reverted after all handlers have fired.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: this.shipDied firing repeatedly in shipScript....1.76

Post by Eric Walch »

Now looking at the code again, I remember why I never thought of fixing it. The player is handled very different in this than the NPC ship.

The player fist explodes, is set to death and than is notified he was killed
The npc is first notified he was killed and than explodes.

To avoid creating all kind of new bugs it seemed easier when scripters would just not try to kill a ship that was already killed. :)

Anyhow, above code fixed things for NCP but bugs the player. Best thing to do is make both consistent and also explode the player after he got the shipDied event. Wonder what new bugs that could introduce?

EDIT:
Committed as r4794. should work correct now, without bugging the player shipDied event.
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: this.shipDied firing repeatedly in shipScript....1.76

Post by Capt. Murphy »

Thanks Eric, I thought it was something along those lines....
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
Post Reply