Issues with latest development build

Today I downloaded the latest development build after uninstalling 3.5. I ran my game, and it threw a NullReferenceException the moment I tried to play a sound. It’s worth noting that I recently switched to a new computer which is connected to a TV screen, with no other source of audio. Before I tried the development build, no exception was thrown, but no audio played.

Also, with the latest installer, the game window starts in a different position from before, with some of the window going past the edge of the screen. That’s not too difficult to fix, I can just manually set the window position, but it is different from before.

Here’s the exception details. Could it be related to XACT?

System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=MonoGame.Framework
StackTrace:
at Microsoft.Xna.Framework.Audio.SoundEffectInstance.PlatformClearFilter()
at Microsoft.Xna.Framework.Audio.SoundEffectInstancePool.GetInstance(Boolean forXAct)
at Microsoft.Xna.Framework.Audio.SoundEffect.GetPooledInstance(Boolean forXAct)
at Microsoft.Xna.Framework.Audio.SoundEffect.Play()
at ThankGoodnessForGravity.SoundManager.PlaySound(SoundEffects effect) in D:\Source\ThankGoodnessForGravity\ThankGoodnessForGravity\ThankGoodnessForGravity\SoundManager.cs:line 46
at ThankGoodnessForGravity.Robot.CheckSequenceSignals() in D:\Source\ThankGoodnessForGravity\ThankGoodnessForGravity\ThankGoodnessForGravity\Robot.cs:line 632
at ThankGoodnessForGravity.Robot.Update() in D:\Source\ThankGoodnessForGravity\ThankGoodnessForGravity\ThankGoodnessForGravity\Robot.cs:line 257
at ThankGoodnessForGravity.Level.Update() in D:\Source\ThankGoodnessForGravity\ThankGoodnessForGravity\ThankGoodnessForGravity\Level.cs:line 65
at ThankGoodnessForGravity.Game1.Update(GameTime gameTime) in D:\Source\ThankGoodnessForGravity\ThankGoodnessForGravity\ThankGoodnessForGravity\Game1.cs:line 168
at Microsoft.Xna.Framework.Game.DoUpdate(GameTime gameTime)
at Microsoft.Xna.Framework.Game.Tick()
at MonoGame.Framework.WinFormsGameWindow.RunLoop()
at MonoGame.Framework.WinFormsGamePlatform.RunLoop()
at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior)
at ThankGoodnessForGravity.Program.Main() in D:\Source\ThankGoodnessForGravity\ThankGoodnessForGravity\ThankGoodnessForGravity\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

@Tom did some work on XACT, so something might have broke…

Not XACT specifically, but maybe related to the changes to support audio effects on the underlying sound system.

In fact I think I see the bug here…

https://github.com/mono/MonoGame/blob/develop/MonoGame.Framework/Audio/SoundEffectInstance.XAudio.cs#L309

My guess is that _voice is still null at this point. I’ll investigate and setup a fix.

Are you using the Windows DirectX platform or Desktop GL?

I’m using DirectX. I would try it with DesktopGL, but I don’t have access to my main dev PC at the moment.

And, I just tried the same project on my laptop, using the latest development build, and ran into the same two issues, which means it’s probably not system-dependent.

More curiously, I started a new project, added a random wav file to content, loaded it using Content.Load, and then added this code to the Update method:

if (Keyboard.GetState().IsKeyDown(Keys.Space) && !soundPlayed)
{
     soundPlayed = true;
     effect.Play();
}

Pressing space will not throw an exception, but it also won’t play a sound. It does reach effect.Play(), though, which I checked using Run to Cursor.

If I get rid of the check for if the sound has already been played, though, an exception is thrown.

if (Keyboard.GetState().IsKeyDown(Keys.Space))
{
     soundPlayed = true;
     effect.Play();
}

Both machines are running Windows 10.

One more note. I changed the code in the Update method to this:

if (Keyboard.GetState().IsKeyDown(Keys.Space))
{
     if (!keyDown)
     {
          soundPlayed = true;
          effect.Play();
     }
     keyDown = true;
}
else keyDown = false;

This ensures that effect.Play() is only called the moment the space bar is pressed.
I ran the program and pressed the space bar once, and no exception was thrown. After waiting until the sound should definitely have finished playing, I pressed the space bar again, and then got the NullReferenceException. This seems to imply that the issue occurs only when a SoundEffect has been played more than once.

FYI. https://github.com/mono/MonoGame/pull/5009

I’ve confirmed that with that PR merged, the exception is no longer thrown. Now I just need to figure out why I’m getting no sound at all.