rds1983 / Myra

UI Library for MonoGame, FNA and Stride
MIT License
703 stars 94 forks source link

Combobox:NullReferenceException #457

Closed Kubrix closed 2 months ago

Kubrix commented 2 months ago
public class Game1 :Game
{
ComboBox CbShootMode;
}

protected override void LoadContent()
{
CbShootMode = new ComboBox();

CbShootMode.Items.Add(new ListItem("Manual", Color.Black));
CbShootMode.Items.Add(new ListItem("Auto", Color.Black));
CbShootMode.Left = 185;
CbShootMode.Top= 50;
grid.Widgets.Add(CbShootMode);
}

protected override void Draw(GameTime gameTime)
{
CbShootMode.Visible = (CurGameState == GameState.Options);

_spriteBatch.Begin();
_desktop.Render();
}

On CbShootMode.Visible = CurGameState == GameState.Options:

System.NullReferenceException: 'Object reference not set to an instance of an object.'

CbShootMode was null.

rds1983 commented 2 months ago

I think the real code differs from the one provided in this issue. As CbShootMode can't be null in such case.

Kubrix commented 2 months ago

Seems to be gone after studio restart and rebuild