HomeWildfire Games

Replace DataTemplateManager simulation component with a globalscript, refs…
AuditedrP20737

Description

Replace DataTemplateManager simulation component with a globalscript, refs #4868.

Removes the serialization of JSON files, shrinking savegame files and rejoin states sent across the network, refs #3834, #4239, #3909, rP18100.
Removes the AI C++ code to read JSON files from rP13225 since the AI can now use the globalscript.
Allows the AI to read Aura templates and removal of GUIInterface code to improve performance.
Serialization of the JSON objects in other simulation components was removed in r20606 / D1109, r20610 / D1130.

Serialization removal planned by sanderd17
AI part proofread by mimo
Simulation part proofread by bb
Discussed with Itms on irc

Differential Revision: https://code.wildfiregames.com/D1108

Event Timeline

mimo raised a concern with this commit.Jan 3 2018, 1:40 PM
mimo added a subscriber: mimo.

Aura serialization bug triggered when player defeated following rP20737
To reproduce, load one of the sandbox demo maps (i've tested sandbox-cart) to have a lots of auras, save it and resign: everything should be fine. Then reload the saved game and resign again. This will trigger the error

ERROR: Script message handler OnOwnershipChanged failed
ERROR: Script message handler OnOwnershipChanged failed
ERROR: Script message handler OnOwnershipChanged failed
ERROR: Script message handler OnOwnershipChanged failed
ERROR: Script message handler OnOwnershipChanged failed
ERROR: Script message handler OnGlobalOwnershipChanged failed
ERROR: Script message handler OnGlobalOwnershipChanged failed
ERROR: Script message handler OnGlobalOwnershipChanged failed
ERROR: Script message handler OnGlobalOwnershipChanged failed
ERROR: Script message handler OnGlobalOwnershipChanged failed
ERROR: Script message handler OnGlobalOwnershipChanged failed
ERROR: Script message handler OnGlobalOwnershipChanged failed
ERROR: JavaScript error: simulation/components/AuraManager.js line 184
TypeError: this.templateModificationsCache.get(...).get(...).get(...) is undefined
  AuraManager.prototype.RemoveTemplateBonus@simulation/components/AuraManager.js:184:2
  Auras.prototype.RemoveTemplateBonus@simulation/components/Auras.js:393:1
  Auras.prototype.Clean@simulation/components/Auras.js:222:4
  Auras.prototype.OnOwnershipChanged@simulation/components/Auras.js:455:2
  Player.prototype.SetState@simulation/components/Player.js:445:1
  g_Commands.resign@simulation/helpers/Commands.js:449:3
  ProcessCommand@simulation/helpers/Commands.js:47:3

I've tried rP20736 which does not trigger the error, while rP20737 does.

This commit now has outstanding concerns.Jan 3 2018, 1:40 PM
gameboy added a subscriber: gameboy.Jan 4 2018, 9:42 AM

As reported by mimo in ​Phab:rP20737, the commit introduced this error when deserializing and resigning a game while some auras were applied:
ERROR: Script message handler OnOwnershipChanged failed
ERROR: Script message handler OnOwnershipChanged failed
ERROR: Script message handler OnOwnershipChanged failed
ERROR: Script message handler OnOwnershipChanged failed
ERROR: Script message handler OnOwnershipChanged failed
ERROR: Script message handler OnGlobalOwnershipChanged failed
ERROR: Script message handler OnGlobalOwnershipChanged failed
ERROR: Script message handler OnGlobalOwnershipChanged failed
ERROR: Script message handler OnGlobalOwnershipChanged failed
ERROR: Script message handler OnGlobalOwnershipChanged failed
ERROR: Script message handler OnGlobalOwnershipChanged failed
ERROR: Script message handler OnGlobalOwnershipChanged failed
ERROR: JavaScript error: simulation/components/AuraManager.js line 184
TypeError: this.templateModificationsCache.get(...).get(...).get(...) is undefined

AuraManager.prototype.RemoveTemplateBonus@simulation/components/AuraManager.js:184:2
Auras.prototype.RemoveTemplateBonus@simulation/components/Auras.js:393:1
Auras.prototype.Clean@simulation/components/Auras.js:222:4
Auras.prototype.OnOwnershipChanged@simulation/components/Auras.js:455:2
Player.prototype.SetState@simulation/components/Player.js:445:1
g_Commands.resign@simulation/helpers/Commands.js:449:3
ProcessCommand@simulation/helpers/Commands.js:47:3

The error can be reproduced from command line on turn 1 using
pyrogenesis -replay="/path/to/commands.txt" -mod=public -rejointest=1

elexis added a comment.Jan 4 2018, 6:00 PM

Thanks for the report mimo!
Thanks for pasting the contents of #4924 here gameboy ;-)

(Progress update yesterday: I noticed after deserialization that the Aura and AuraManager contents seem to be correct and the aura is still applied, the aura icon is rendered on top of the head of the affected unit, but somehow the aura range is not rendered. Could reproduce it on a map with only 2 entities.)

/ps/trunk/binaries/data/mods/public/simulation/components/Auras.js
56

Independent from this diff:

Using this[name] without restricting name is bad practice. It breaks the code if an aura would use a name that is coincidentally a property of the aura component JS object.

There is a patch here, and this patch may help us to solve this problem.

https://trac.wildfiregames.com/attachment/ticket/4924/superhackylolnopeuneval.patch

gameboy added a comment.EditedJan 5 2018, 10:58 AM

I got a similar mistake:

ERROR: Script message handler OnPlayerDefeated failed
ERROR: Script message handler OnPlayerDefeated failed
ERROR: Script message handler OnPlayerDefeated failed
ERROR: Script message handler OnPlayerDefeated failed
ERROR: Script message handler OnPlayerDefeated failed
ERROR: Script message handler OnPlayerDefeated failed
ERROR: Script message handler OnPlayerDefeated failed
ERROR: Script message handler OnPlayerDefeated failed
ERROR: Script message handler OnPlayerDefeated failed
ERROR: Script message handler OnPlayerDefeated failed
ERROR: Script message handler OnGlobalPlayerDefeated failed
ERROR: JavaScript error: simulation/components/AuraManager.js line 184 TypeError: this.templateModificationsCache.get(...).get(...).get(...) is undefined AuraManager.prototype.RemoveTemplateBonus@simulation/components/AuraManager.js:184:2 Auras.prototype.RemoveTemplateBonus@simulation/components/Auras.js:393:1 Auras.prototype.Clean@simulation/components/Auras.js:222:4 Auras.prototype.OnPlayerDefeated@simulation/components/Auras.js:485:2 Player.prototype.SetState@simulation/components/Player.js:452:1 Trigger.prototype.ConquestOwnershipChanged@maps/scripts/ConquestCommon.js:23:5 Trigger.prototype.DoAction@simulation/components/Trigger.js:331:3 Trigger.prototype.CallEvent@simulation/components/Trigger.js:225:4 Trigger.prototype.OnGlobalOwnershipChanged@simulation/components/Trigger.js:270:2
ERROR: Script message handler OnGlobalOwnershipChanged failed
elexis requested verification of this commit.Jan 25 2018, 5:47 PM

All reported errors should be fixed by rP21014 and the Auras, AuraManager and TechnologyManager should have no other surface area for OOS on rejoin errors.

Thanks for the report, I never noticed it otherwise when testing!

This commit now requires verification by auditors.Jan 25 2018, 5:47 PM
mimo accepted this commit.Jan 26 2018, 6:39 PM
All concerns with this commit have now been addressed.Jan 26 2018, 6:39 PM