0

Recently, my crash manager has emailed me a crash from a game that I'm working on.

    System.ArgumentException: Exception from HRESULT: 0x80070057 (E_INVALIDARG)
       at System.Globalization.CultureInfo.nativeSetThreadLocale(String localeName)
       at System.Threading.Thread.set_CurrentCulture(CultureInfo value)
       at Siphon_Spirit.Game1.Initialize()
       at Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun)
       at Siphon_Spirit.Program.Main(String[] args)

Since it was automatically emailed, I don't know where the user was located, but it seems that for their machine InvariantCulture is not set up or something.

In my initialize method I use the following code. I believe that only the two lines setting the CurrentCulture and the CurrentUICulture are causing issues.

protected override void Initialize()
    {
        this.IsMouseVisible = false;
        SetFullScreen(true);            
        SaveController.LoadOptions();
        screenManager = new Screens.ScreenManager();
        screenManager.Initialize();
        graphics.ApplyChanges();
        Window.Title = "Siphon Spirit";
        SaveController.Initialize();
        rendertarget = new RenderTarget2D(GraphicsDevice, GlobalData.ScreenWidth, GlobalData.ScreenHeight);

        debugger = new Debugger();
        Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
        Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.InvariantCulture;
        base.Initialize();
    }

Any ideas as to what is making it crash? This seems to be an isolated case, as more people have run it with no issues.

Califer
  • 529
  • 9
  • 28
  • Side note: I don't think `InvariantCulture` is supposed to be used as global culture... Try to set to EN-US (which is mostly equivalent of Invariant one, but real and likely supported by OS, unlike invariant). – Alexei Levenkov Oct 04 '13 at 17:29
  • @AlexeiLevenkov What do you mean by `I don't think InvariantCulture is supposed to be used as global culture`? `InvariantCulture` is pretty much supported.(Not sure about XNA) – Sriram Sakthivel Oct 04 '13 at 17:45
  • 1
    I agree with Alexei, InvariantCulture is a synthetic culture and is likely to cause trouble on a machine that boots XP. Changing the thread culture is a risky proposition, worker threads still use the default culture and that can cause lots of subtle problems. This didn't get addressed until .NET 4.5 with the addition of the CultureInfo.DefaultThreadXxx properties. – Hans Passant Oct 04 '13 at 18:21
  • @SriramSakthivel - see Hans Passant's comment. Invariant is perfectly fine to be explicitly used in parsing/formatting calls, but I'd be very worried with code that sets thread-global (`Thread.CurrentThread.CurrentUICulture`/`CurrentCulture`) to it. – Alexei Levenkov Oct 04 '13 at 18:36
  • @AlexeiLevenkov But it helped for me all the time. Works in winform, console app. and so I said it is supported – Sriram Sakthivel Oct 04 '13 at 18:40
  • I'll switch over the EN-US and see if I get any more crashes. Since I don't know who was making it crash I'll just have to hope they try again. Thanks for all the help! – Califer Oct 04 '13 at 20:23

0 Answers0