Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Startup crash when speakers are not plugged in #4717

Closed
tomspilman opened this issue Apr 3, 2016 · 7 comments

Comments

@tomspilman
Copy link
Member

commented Apr 3, 2016

I've learned that XAudio device creation fails if there are no speakers plugged into the PC. That is weird... it is like DirectX failing to initialized because there is no monitor plugged in.

http://stackoverflow.com/questions/35600946/why-oncriticalerror-is-called-in-directx-version-of-xaudio2

Not sure if the OpenAL path suffers from this as well.

MonoGame should be able to internalize this and keep it from being an issue the game developer has to deal with.

@lozzajp

This comment has been minimized.

Copy link
Contributor

commented Nov 2, 2016

Reading 4715; this issue replicates what XNA does but we want it better?

Is this at runtime when a game starts, in either XNA or MonoGame will crash if it can't find hardware to create an audio device from?

@theZMan

This comment has been minimized.

Copy link
Contributor

commented Nov 2, 2016

If we changed this behavior then all the existing code that relies on XNA throwing an exception wouldn't work the same ;-)

@patridge

This comment has been minimized.

Copy link

commented Apr 29, 2018

I have this error happening out of the Microsoft.Xna.Framework.Game constructor when I call base(), so I'm trying to figure out how to even add code that relies on this exception. If it is throwing an exception in the base constructor every time, how would you rely on that exception in a way that isn't horrible for the user? How do you spin up anything useful for the user without an audio device connected? Do you just try-catch around the game constructor and show an alert before ultimately exiting to desktop?

@Halofreak1990

This comment has been minimized.

Copy link

commented May 31, 2018

Odd place for an exception like this, and not how XNA does things;. XNA will throw a NoAudioHardwareException only when you actually try to use the audio subsystem, either by initializing the XACT classes or by attempting to play audio using the SoundEffect or Song classes. As long as you don't do that, you should be safe.

I think that the MonoGame code should be changed to lazily initialize the audio subsystem when first used.

@patridge

This comment has been minimized.

Copy link

commented May 31, 2018

Even if the audio system was lazily initialized, it doesn't seem like the game should necessarily have to care about there not being audio hardware. Even if a game tries to play audio on a system with no way to do so, it should just carry on like it worked (potentially offering a way to detect the no-hardware situation for user-facing troubleshooting messaging). It feels like there shouldn't really be a NoAudioHardwareException as much as a HasAudioHardware property somewhere.

@Halofreak1990

This comment has been minimized.

Copy link

commented May 31, 2018

@patridge

Even if a game tries to play audio on a system with no way to do so, it should just carry on like it worked (potentially offering a way to detect the no-hardware situation for user-facing troubleshooting messaging).

That's what the exception is for ;)
You catch it, set a flag to not use audio from that point forward, and you're good.

It feels like there shouldn't really be a NoAudioHardwareException as much as a HasAudioHardware property somewhere.

True, but that's the way XNA does it. And probably the way MonoGame should do, too, as long as they're trying to emulate XNA.

@mrhelmut

This comment has been minimized.

Copy link
Contributor

commented Feb 10, 2019

There is now a mechanism to detect this and proceed without sound if need be: #6629

@Jjagg Jjagg closed this Feb 10, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.