From 7386816f52f30d15e5455f1ea4591c80e1a3fc15 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Sun, 24 May 2020 19:39:07 +0200 Subject: [PATCH] Manually construct the PlayerActor to fix crashes during actor creation --- OpenRA.Game/Player.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index 9c584bbefc..dda05e658e 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -166,8 +166,16 @@ namespace OpenRA if (!Spectating) PlayerMask = new LongBitSet(InternalName); + // Special case handling is required for the Player actor: + // Since Actor.Created would be called before PlayerActor is assigned here + // querying player traits in INotifyCreated.Created would crash. + // Therefore only call the constructor of Actor and run the Created callbacks ourselves. + // Add the PlayerActor to the world afterwards. var playerActorType = world.Type == WorldType.Editor ? EditorPlayerActorType : PlayerActorType; - PlayerActor = world.CreateActor(playerActorType, new TypeDictionary { new OwnerInit(this) }); + PlayerActor = new Actor(world, playerActorType, new TypeDictionary { new OwnerInit(this) }); + PlayerActor.Created(); + world.Add(PlayerActor); + Shroud = PlayerActor.Trait(); FrozenActorLayer = PlayerActor.TraitOrDefault();