Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#3187 closed defect (fixed)

[PATCH] setup-trade-route - undefined property cmd.source

Reported by: elexis Owned by: leper
Priority: Should Have Milestone: Alpha 19
Component: UI & Simulation Keywords: patch
Cc: Patch:

Description

In an a18 match this error occured:

Turn 2099 (500)... WARNING: JavaScript warning: simulation/helpers/Commands.js line 582
reference to undefined property cmd.source

The according code in Commands.js is:

	"setup-trade-route": function(player, cmd, data)
	{
		GetFormationUnitAIs(data.entities, player).forEach(function(cmpUnitAI) {
			cmpUnitAI.SetupTradeRoute(cmd.target, cmd.source, cmd.route, cmd.queued);
		});
	},

Error reproducable with the attached commands.txt.

Maybe my ally setup a trade route while my market was not completely built yet.

Attachments (4)

t3187_commands.txt_replaylog.7z (107.0 KB ) - added by elexis 9 years ago.
commands.txt (15.5 KB ) - added by elexis 9 years ago.
Alternative commands.txt with same error. Almost there…
t3187_fix_undefined_property_traderoute.patch (940 bytes ) - added by elexis 9 years ago.
t3187_fix_undefined_property_traderoute_trompetin17.patch (788 bytes ) - added by elexis 9 years ago.
Alternative patch by trompetin17. Tested and works too.

Download all attachments as: .zip

Change History (11)

by elexis, 9 years ago

comment:1 by elexis, 9 years ago

Player 1 and 2 were allied. Every player had only one market. Player 1 never had any trade carts. Player 2 only had those 2 trade carts that cause the error. No other commands refer to those markets and trade carts.

The entity ID of the market of player 1 is 5155 and the one of player 2 is 5246. The entity ID of the two trade carts of player 2 that caused the error are 5580 and 5637.


Chronological order of all events refering to those entities:

Player 1 started to build the market on turn 1405:

cmd 1 {"type":"construct","template":"structures/cart_market","x":637.8291015625,"z":1193.99365234375,"angle":2.356194490192345,"actorSeed":63789,"entities":[4610],"autorepair":true,"autocontinue":true,"queued":false}

Player 2 started to build the market on turn 1654:

cmd 2 {"type":"construct","template":"structures/athen_market","x":1014.2716064453125,"z":840.1791381835938,"angle":2.356194490192345,"actorSeed":18852,"entities":[207,3089,3110,3119,3214],"autorepair":true,"autocontinue":true,"queued":false}

The market of player 1 was already built on turn 1738:

cmd 1 {"type":"research","entity":5155,"template":"speed_trader_01"}

The market of player 2 was already built on turn 2011:

cmd 2 {"type":"research","entity":5246,"template":"speed_trader_01"}
cmd 2 {"type":"train","template":"units/athen_support_trader","count":1,"entities":[5246]}
cmd 2 {"type":"train","template":"units/athen_support_trader","count":1,"entities":[5246]}

Player 2 stopped the trade speed increase upgrade research on turn 2013:

cmd 2 {"type":"stop-production","entity":5246,"id":1}

ERROR: Then player 2 sent his trade carts to the market of player 1 on turn 2099, which is the turn number on which the error occured:

cmd 2 {"type":"setup-trade-route","entities":[5580,5637],"target":5155,"queued":false}

After the error occured player 2 setup the trade route again on turn 2324, indicating that the traderoute setup really failed before:

cmd 2 {"type":"setup-trade-route","entities":[5580,5637],"target":5246,"queued":false}

by elexis, 9 years ago

Attachment: commands.txt added

Alternative commands.txt with same error. Almost there...

comment:2 by elexis, 9 years ago

I can reproduce the error in a18 and svn by following those steps:

-make market with both players -make a trade cart with one player -select the cart and right click the market of the other player

Strangely enough the error doesn't appear ingame, but it appears when replaying the commands.txt afterwards. Not sure why the error was displayed in the original game.

comment:3 by elexis, 9 years ago

Milestone: BacklogAlpha 19
Summary: setup-trade-route - undefined property cmd.source[PATCH] setup-trade-route - undefined property cmd.source

comment:4 by elexis, 9 years ago

As it turns out, the error only appears when replaying the commands.txt, but not ingame. That is because the cmd.source property of the setup-trade-route command will not be saved to commands.txt if the value is undefined. So I simply changed it to null. The same has to be done to the route property.

I tested the patch with the most recent svn version (16564) and setting up a trade route still works and the error disappeared when replaying the commands.txt.

The patch should work in theory too, because the only place where the source property is checked is in Trader.js in Trader.prototype.SetTargetMarket:

	if (source)

and this should have the same result for null as for undefined.

comment:5 by elexis, 9 years ago

Keywords: patch review added

by elexis, 9 years ago

Alternative patch by trompetin17. Tested and works too.

comment:6 by leper, 9 years ago

Owner: set to leper
Resolution: fixed
Status: newclosed

In 16566:

Pass some properties as null instead of undefined to circumvent serializer limitations. Based on patch by elexis. Fixes #3187.

comment:7 by leper, 9 years ago

Component: Core engineUI & Simulation
Keywords: review removed

Thanks.

Note: See TracTickets for help on using tickets.