Opened 5 years ago

Closed 3 years ago

#5589 closed defect (fixed)

PETRA.getLandAccess gamePosToMapPos p is undefined common-api/map-module.js

Reported by: Freagarach Owned by: Silier
Priority: Must Have Milestone: Alpha 24
Component: AI Keywords:
Cc: Krinkle Patch: Phab:D3244

Description

SVN 22882. At turn 1092 an error occurred:

ERROR: JavaScript error: simulation/ai/common-api/map-module.js line 44
TypeError: p is undefined 

http://irclogs.wildfiregames.com/2019-09/2019-09-10-QuakeNet-%230ad-dev.log

Attachments (2)

commands-modif.txt (25.5 KB ) - added by Freagarach 5 years ago.
Replay.
p_is_undefined.tar.gz (1.1 MB ) - added by oumph 3 years ago.
Commands + metadata + screenshot

Download all attachments as: .zip

Change History (11)

by Freagarach, 5 years ago

Attachment: commands-modif.txt added

Replay.

comment:1 by Freagarach, 5 years ago

(First posted at rP22878.)

comment:2 by elexis, 5 years ago

The replay produces the same error on r22893:

ERROR: JavaScript error: simulation/ai/common-api/map-module.js line 44
TypeError: p is undefined
  m.Map.prototype.gamePosToMapPos@simulation/ai/common-api/map-module.js:44:10
  m.Accessibility.prototype.getAccessValue@simulation/ai/common-api/terrain-analysis.js:145:16
  PETRA.getLandAccess@simulation/ai/petra/entityExtend.js:72:1
  PETRA.AttackPlan.prototype.updatePreparation@simulation/ai/petra/attackPlan.js:551:15
  PETRA.AttackManager.prototype.update@simulation/ai/petra/attackManager.js:264:21
  PETRA.HQ.prototype.update@simulation/ai/petra/headquarters.js:2766:3
  PETRA.PetraBot.prototype.OnUpdate@simulation/ai/petra/_petrabot.js:118:3
  m.BaseAI.prototype.HandleMessage@simulation/ai/common-api/baseAI.js:64:2

Map was neareastern_badlands.js.

comment:3 by elexis, 5 years ago

Summary: AI common-api pathfinder bug.PETRA.getLandAccess gamePosToMapPos p is undefined common-api/map-module.js

Tested using:

Index: binaries/data/mods/public/simulation/ai/petra/entityExtend.js
===================================================================
--- binaries/data/mods/public/simulation/ai/petra/entityExtend.js	(revision 22892)
+++ binaries/data/mods/public/simulation/ai/petra/entityExtend.js	(working copy)
@@ -69,6 +69,13 @@
 PETRA.getLandAccess = function(gameState, ent)
 {
 	if (ent.hasClass("Unit"))
+		if (!ent.position())
+		{
+			warn(uneval(ent.id()))
+			warn(uneval(ent.templateName()))
+		}
+
+	if (ent.hasClass("Unit"))
 		return gameState.ai.accessibility.getAccessValue(ent.position());
 
 	let access = ent.getMetadata(PlayerID, "access");

It is entity 878 and that entity has no position, it is a units/brit_infantry_spearman_b. So that unit promoted or died that turn.

Then it sounds like either the bot should disregard the unit at that point or actively remove the unit from its knowledge. Perhaps upon destruction / rename, though I guess it doesnt get those messages? I have no experience.

Same error stack at r15664 / #2741.

Last edited 5 years ago by elexis (previous) (diff)

comment:4 by Krinkle, 5 years ago

Cc: Krinkle added

comment:5 by oumph, 3 years ago

Debian package 0.0.23.1-5

Map "Greek Acropolis (2)"

Happened at the very end, twice.

Attachment with metadata.json, commands.txt, and screenshot

Last edited 3 years ago by oumph (previous) (diff)

by oumph, 3 years ago

Attachment: p_is_undefined.tar.gz added

Commands + metadata + screenshot

comment:6 by Silier, 3 years ago

Priority: Should HaveMust Have

comment:7 by Silier, 3 years ago

Actually position is undefined if entity is out of world, so might be garrisoned

comment:8 by Silier, 3 years ago

Milestone: BacklogAlpha 24
Patch: Phab:D3244

comment:9 by Silier, 3 years ago

Owner: set to Silier
Resolution: fixed
Status: newclosed

In 24436:

[Petra/Ai] Get landaccess of garrison holder if entity is garrisoned

Position of garrisoned entities is undefined, thats why landaccess fails, when asking for position in some cases.
Last replay in ticket is from a23b.

source of the issue was this.target in attackplan got garrisoned so it got undefined possition.

Solution applied is to ask for landaccess of garrisonholder if current entity is garrisoned inside the function itself, instead doing it in every place possible and forget it the future additions. If calling code does not want to deal with garrisoned entities, it should check for that case separately.

For attack plan, when it happened is fine, because it will deal with garrisoned entity later.

Differential revision: D3244
Fixes: #5589

Note: See TracTickets for help on using tickets.