Correction: Component “Parent” Set Accessor
The “Set” accessor in the Component’s “Parent” property should be changed to the following to avoid a condition where a component’s would be “orphaned” (have its “parent” property set to null and not appear in any GameScreen’s list of components) when its parent is set to the same value.
public GameScreen Parent
{
get { return parent; }
set
{
if (parent == value)
return;
if (parent != null)
parent.RemoveComponent(this);
parent = value;
if (value != null)
parent.AddComponent(this);
}
}
Thanks go to “Shane” for finding this bug. And for making me actually run all the stack traces to check my code instead of lazily assuming it would work.

[...] Correction: Component “Parent” Set Accessor [...]
Why I have such feeling that this the Parent property is the same as in the GameScreen article
so do i worry about this after building the gamescreen?
=
If this is only set via the GameScreen.AddComponent() method then the last two lines are not needed since all they do is create a loop, I haven’t seen this property set from anywhere else so I think this is the case, the loop is stopped by the AddComponent() method checking if the component is already in it’s list however so it’s not that bad I suppose
=
=