LorisYounger / VPet

虚拟桌宠模拟器 一个开源的桌宠软件, 可以内置到任何WPF应用程序
Apache License 2.0
4.79k stars 476 forks source link

App crashes in another region #25

Closed Afireal closed 1 year ago

Afireal commented 1 year ago

Seems like app just crashes on Core mod loading because of lack of a localization for system region. Setting it to English (USA) in Win settings fixes the issue but idk it's not really a nice way. How about automaticlly setting localization to EN if there is no lang files for system language?

LorisYounger commented 1 year ago

In theory, it should automatically switch to English And loading an empty language will not result in an error I will add an automatic switch to English in the next update if the current language is empty

LorisYounger commented 1 year ago

I update a new version, can you open now?

Afireal commented 1 year ago

I managed to compile latest VPet-Simulator.Windows and that's what I got. Localization is automaticlly switching to EN without latest changes (sorry). Fortunatly, I discovered why app crashes exactly on Core mod loading. There's an exception on food initializing.

CoreMOD.cs:137

case "food":
                        Tag.Add("food");
                        foreach (FileInfo fi in di.EnumerateFiles("*.lps"))
                        {
                            var tmp = new LpsDocument(File.ReadAllText(fi.FullName));
                            foreach (ILine li in tmp)
                            {
                                string tmps = li.Find("name").info;
                                mw.Foods.RemoveAll(x => x.Name == tmps);
                                mw.Foods.Add(LPSConvert.DeserializeObject<Food>(li));
                            }
                        }
                        break;

System.FormatException: Input string was not in a correct format. on mw.Foods.Add(LPSConvert.DeserializeObject<Food>(li)); If I compile whole thing with american formats in Win settings, everything is fine. I don't really know much about dotnet, so no ideas.

Afireal commented 1 year ago

Stack trace. But I don't think it's really helpful now


System.FormatException
  HResult=0x80131537
  Message=Входная строка имела неверный формат. <-- Input string was not in a correct format.
  Source=mscorlib
  StackTrace:
   at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
   at System.String.System.IConvertible.ToDouble(IFormatProvider provider)
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at LinePutScript.Converter.LPSConvert.GetStringObject(String value, Type type, ConvertType convtype, LineAttribute att)
   at LinePutScript.Converter.LPSConvert.GetSubObject(ISub sub, Type type, ConvertType convtype, LineAttribute att)
   at LinePutScript.Converter.LPSConvert.DeserializeObject[T](ISub value)
   at VPet_Simulator.Windows.CoreMOD..ctor(DirectoryInfo directory, MainWindow mw) in E:\Git\VPet\VPet-Simulator.Windows\Function\CoreMOD.cs:line 137
   at VPet_Simulator.Windows.MainWindow.<GameLoad>d__107.MoveNext() in E:\Git\VPet\VPet-Simulator.Windows\MainWindow.xaml.cs:line 208```
LorisYounger commented 1 year ago

I think that's the real reason for the error report. I'll study how to solve it. Thank you for your feedback. It really helped a lot

Afireal commented 1 year ago

That's so stupid, but it's real. This converter or smth else in the code can't accept a comma as a decimal separator. If I change it to point in Win Control Panel without completely switching to American standards, it will work. LMAO Looks like somewhere in the converter code, there is no lookup for system formats, but hardcoded point.

LorisYounger commented 1 year ago

I'm sorry, I wrote this LinePutScript I may find a solution and try to lock the language to en US

Convert.ChangeType(Sub.TextDeReplace(value), type, new CultureInfo("en-US"));

but I am not sure is that work, I will compile a beta version. Can you help me test it

Afireal commented 1 year ago

ok, no problem

LorisYounger commented 1 year ago

LinePutScript.zip rereplace it with LinePutScript.dll is game working?

Afireal commented 1 year ago

Nope. Neither the steam version nor the compiled one

LorisYounger commented 1 year ago

Can you use visual studio Reference this DLL and run again? I want to see is same error or different

Afireal commented 1 year ago

Different one, but still the same exception. I will now send details

Afireal commented 1 year ago

VPet-Simulator.Core/Graph/FoodAnimation.cs:151

                    if (strs.Length > 4)
                    {
                        Rotate = double.Parse(strs[4]);//Rotate
                        if (strs.Length > 5)
                            Opacity = double.Parse(strs[5]);//Opacity
                    }

Same System.FormatException: Input string was not in a correct format. on double.Parse(strs[5])

Stack trace

System.FormatException
  HResult=0x80131537
  Message=Входная строка имела неверный формат.
  Source=mscorlib
  StackTrace:
   at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
   at System.Double.Parse(String s)
   at VPet_Simulator.Core.FoodAnimation.Animation..ctor(FoodAnimation parent, ISub sub) in E:\Git\VPet\VPet-Simulator.Core\Graph\FoodAnimation.cs:line 149
   at VPet_Simulator.Core.FoodAnimation..ctor(GraphCore graphCore, GraphInfo graphinfo, String front_Lay, String back_Lay, ILine animations, Boolean isLoop) in E:\Git\VPet\VPet-Simulator.Core\Graph\FoodAnimation.cs:line 45
   at VPet_Simulator.Core.FoodAnimation.LoadGraph(GraphCore graph, FileSystemInfo path, ILine info) in E:\Git\VPet\VPet-Simulator.Core\Graph\FoodAnimation.cs:line 53
   at VPet_Simulator.Core.PetLoader.LoadGraph(GraphCore graph, DirectoryInfo di, String startuppath) in E:\Git\VPet\VPet-Simulator.Core\Handle\PetLoader.cs:line 94
   at VPet_Simulator.Core.PetLoader.LoadGraph(GraphCore graph, DirectoryInfo di, String startuppath) in E:\Git\VPet\VPet-Simulator.Core\Handle\PetLoader.cs:line 117
   at VPet_Simulator.Core.PetLoader.Graph(Int32 Resolution) in E:\Git\VPet\VPet-Simulator.Core\Handle\PetLoader.cs:line 25
   at VPet_Simulator.Windows.MainWindow.<>c__DisplayClass107_0.<GameLoad>b__7() in E:\Git\VPet\VPet-Simulator.Windows\MainWindow.xaml.cs:line 327
   at System.Windows.Threading.DispatcherOperation.InvokeDelegateCore()
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
LorisYounger commented 1 year ago

Can you add

CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");

at https://github.com/LorisYounger/VPet/blob/main/VPet-Simulator.Windows/MainWindow.xaml.cs#L43

        public MainWindow()
        {
            LocalizeCore.StoreTranslation = true;
            CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
...

and try again?

Afireal commented 1 year ago

Nothing has changed

LorisYounger commented 1 year ago

How about

            CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator = ".";

at https://github.com/LorisYounger/VPet/blob/main/VPet-Simulator.Windows/MainWindow.xaml.cs#L43

        public MainWindow()
        {
            LocalizeCore.StoreTranslation = true;
            CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator = ".";
Afireal commented 1 year ago

System.InvalidOperationException on new line It's says that it's read-only value

LorisYounger commented 1 year ago
            CultureInfo.CurrentCulture = new CultureInfo(CultureInfo.CurrentCulture.Name);
            CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator = ".";

This should be effective

Afireal commented 1 year ago

No effect. Still the same error as here but on line 149

LorisYounger commented 1 year ago
            LocalizeCore.StoreTranslation = true;
            CultureInfo.CurrentCulture = new CultureInfo(CultureInfo.CurrentCulture.Name);
            CultureInfo.CurrentCulture.NumberFormat = new CultureInfo("en-US").NumberFormat;
Afireal commented 1 year ago

It's works!

LorisYounger commented 1 year ago

Thanks for you help!

Afireal commented 1 year ago

Should I close this issue or it's just a temporary solution?

LorisYounger commented 1 year ago

Thank you again for your help, I will update fix to steam soon I will close when the update is complete