Bug in TX2D's use of XNA Framework
by Jason Cahill · in Torque X 2D · 07/13/2009 (4:11 am) · 3 replies
I noticed that my GUIButton controls do not always get the colors I specify in my XML and spent a while debugging it to find that XNA 3.0 has a bug in their constructor for Color(Vector4), which is used by GUIButtonStyle::OnLoaded.
The specific color that caused the problem was:
I noticed that everything worked except ColorHL, which rendered as white. Stepping through the code proved that the bug is in the Color constructor. Here's the fix for those that care. It should be applied to TorqueCoreGUIGUIText (GUITextStyle) and TorqueCoreGUIButton (GUIButtonStyle):
The specific color that caused the problem was:
<TextColors>
<ColorBase><X>255</X><Y>255</Y><Z>255</Z><W>255</W></ColorBase>
<ColorHL><X>254</X><Y>194</Y><Z>43</Z><W>255</W></ColorHL>
<ColorSEL><X>0</X><Y>0</Y><Z>0</Z><W>255</W></ColorSEL>
<ColorNA><X>0</X><Y>0</Y><Z>0</Z><W>255</W></ColorNA>
</TextColors>I noticed that everything worked except ColorHL, which rendered as white. Stepping through the code proved that the bug is in the Color constructor. Here's the fix for those that care. It should be applied to TorqueCoreGUIGUIText (GUITextStyle) and TorqueCoreGUIButton (GUIButtonStyle):
public override void OnLoaded()
{
base.OnLoaded();
for (int i = 0; i < _textColorAsVector4.Count; i++)
{
Vector4 vec = _textColorAsVector4[i];
Color col = new Color();
col.R = (Byte)vec.X;
col.G = (Byte)vec.Y;
col.B = (Byte)vec.Z;
col.A = (Byte)vec.W;
TextColor[(CustomColor)i] = col;
}
}About the author
Torque Owner Jason Cahill
Default Studio Name
I have verified that this fix works correctly and have updated my engine sources.