flibitijibibo / FNA-MGHistory

FNA - Accuracy-focused XNA4 reimplementation for open platforms
http://fna-xna.github.io/
246 stars 37 forks source link

Can't run on machine without audio device #308

Closed AxiomVerge closed 9 years ago

AxiomVerge commented 9 years ago

This bug report is more vague than I'd like, since I've only encountered it when using a non-dev machine.

Basically, some machines - like the cheapo Windows 8 machine I use as a server - consider themselves not to have an audio device until you plug something into the jack (like headphones). When you do, a little notification appears by the tray to let you know it's installing the new device.

If I try to run the game without headphones plugged in, it immediately exits. Plugging in headphones allows it to run.

I'm hoping there is some easy fix I add at startup or the like. But tomorrow I hope to actually test with a debug build to see if I can get better error output.

I had this happen one other time using a loaned machine at an expo.

flibitijibibo commented 9 years ago

Technically this is half-accurate; when there's no audio device XNA should be throwing NoAudioHardwareException, but I think there should be a messagebox that tells you this. @SeanColombo or @darthdurden may be able to explain this in a bit more detail.

For now I'm going to shift some things around to try and at least get the messagebox. I might be able to get you an AudioReferenceDevice too, so you can run without worrying about runtime errors there.

flibitijibibo commented 9 years ago

https://github.com/flibitijibibo/FNA/commit/f7348ffa6199ac3954ef86bc4beba18b7c615b54

This commit should now ensure that the messagebox shows up, which should be more accurate (or at least more informative). I'll throw together a NullDevice now; shouldn't take more than a few minutes.

flibitijibibo commented 9 years ago

Bam:

https://github.com/flibitijibibo/FNA/commit/1d913926a5f64f44ecf4605df849683b97f4c0c7

Set environment variable FNA_AUDIO_DISABLE_SOUND to "1" and it should use the NullDevice. This behavior is completely undefined, but at least it should give you the opportunity to just skip sound. Hopefully this has no effect on performance, but I only tested functionality and not perf... we'll see.

EDIT: This is now documented on the FNA wiki:

https://github.com/flibitijibibo/FNA/wiki/7:-FNA-Environment-Variables#fna_audio_disable_sound

AxiomVerge commented 9 years ago

Ok, I get the message box now, but seem not to be catching the exception correctly (or else I am just not understanding how to use). Here is what I did:

            THGame game = null;
            try
            {
                game = new THGame();
            }
            catch(Microsoft.Xna.Framework.Audio.NoAudioHardwareException e)
            {
                System.Console.WriteLine("No hardware.  Trying to use null device.");
                System.Environment.SetEnvironmentVariable("FNA_AUDIO_DISABLE_SOUND", "1");
                game = new THGame();
            }

            if (game != null)
            {
                try
                {
                    game.Run();
                }
                finally
                {
                    game.Dispose();
                }
            }

I also tried a plain ole'

            catch(Exception e)

-but nothing happened.

flibitijibibo commented 9 years ago

If you happen to have a debugger handy, make sure it's actually creating a NullDevice (or worst case, throw a printf in that block). The first NoAudioHardwareException still makes sense, but the second crash does not...

Sent from my iPhone

On Apr 25, 2015, at 17:53, Tom Happ notifications@github.com wrote:

Ok, I get the message box now, but seem not to be catching the exception correctly (or else I am just not understanding how to use). Here is what I did:

        THGame game = null;
        try
        {
            game = new THGame();
        }
        catch(Microsoft.Xna.Framework.Audio.NoAudioHardwareException e)
        {
            System.Console.WriteLine("No hardware.  Trying to use null device.");
            System.Environment.SetEnvironmentVariable("FNA_AUDIO_DISABLE_SOUND", "1");
            game = new THGame();
        }

        if (game != null)
        {
            try
            {
                game.Run();
            }
            finally
            {
                game.Dispose();
            }
        }

I also tried a plain ole'

        catch(Exception e)

-but nothing happened.

— Reply to this email directly or view it on GitHub.

flibitijibibo commented 9 years ago

FWIW, I'm now officially out of town but if you want to send me test cases I can still debug on my end as well. Doesn't have to be Linux/Mac, I can debug Windows assemblies without any fuss.

flibitijibibo commented 9 years ago

I sat down with XNA4 and looked into this. It turns out XNA actually has an unhandled Exception handler internally, which calls ShowMissingRequirementMessage. So, the messagebox only shows up when you don't catch the Exception:

https://github.com/flibitijibibo/FNA/commit/2d7d608459697fa7fad3c953faac37f9b4cd34b3

If you catch this properly the messagebox will not show up, and if not, you should expect the application to crash in these scenarios (though at least a messagebox will show up, right?).

This should now behave accurately, though it should probably be tested locally.

flibitijibibo commented 9 years ago

Closing due to old age, but as far as I can tell this should now be accurate. If an AV customer happens to try playing with no sound card we might find out for sure... >_>

AxiomVerge commented 9 years ago

I'm sorry, I should have mentioned - I did test it, and it works. Thank you!