Alright, I'm having a really odd issues. I'm right now writing a simple game in C#/MonoGame (on Linux). I'm trying to play a SoundEffect
. When I call Play()
(even though it's been properly loaded in the LoadContent()
method). It's throwing a NullReferenceException
with the message Object Reference not set to an instance of an object
.
Here is how the code is structured
public class MyGame : Game
{
// ..
private SoundEffect _sfx;
public PingGame ()
{
// ...
}
protected override void Initialize ()
{
// ...
}
protected override void LoadContent ()
{
// ...
// No errors here on loading it
_sfx = Content.Load<SoundEffect>("noise.wav");
}
protected override void Update (GameTime gameTime)
{
// ...
if (playSound)
{
// This is where the error is thrown
_sfx.Play();
}
// ...
}
protected override void Draw (GameTime gameTime)
{
// ..
}
}