HaxeFoundation / hxcpp

Runtime files for c++ backend for haxe
Other
295 stars 184 forks source link

Crash with executables for windows target when non-ASCII chars present in exe path #1019

Closed IPv6 closed 1 year ago

IPv6 commented 1 year ago

Situation: i have a game that works on windows without a problem BUT does not start when there is non-ASCII characters in path (unicode). It was compiled with HXCPP 4.2.1 on Win10, release build. I recompiled game with HXCPP_CHECK_POINTER / HXCPP_STACK_TRACE / HXCPP_STACK_LINE / HXCPP_DEBUG_LINK and started ProcMon from sysinternals and there is a clear stacktrace of the point where everything crashes (with C0000005), look at screenshot ( full stacktrace here - https://pastebin.com/GiawsUVk ). The path like "C:_WPLabs\Downloads\ЙЙЙЦЦвsdfываываыва\AppMain.exe" produce C0000005 crash

App craches during ParseCommandLine in "String::operator+=" at \haxe\lib\hxcpp\4,2,1\src\hx\StdLibs.cpp(419) In 4.2.1 this is following strings:

    // We have now identified arg0 as pStart (or pStart+1 if we have a leading
    // quote) through psrc-1 inclusive
    if (skipQuote)
        pStart++;
    String arg0("");
    while (pStart < psrc)
    {
        arg0 += String::fromCharCode(*pStart);
        pStart++;
    }
    // out.Add(arg0); // the command isn't part of Sys.args()

Seems the problem in String::fromCharCode. I commented "arg0+=..." and recompile the code (game does not use command line at all) - and the problems was gone! No further crashes. For me this confirms something definitely off here

2022-11-17_12-23-23

IPv6 commented 1 year ago

BTW, seems this crash exist for 2 years already: https://community.openfl.org/t/windows-target-crash-if-executable-path-contain-non-english-characters/12770

hughsando commented 1 year ago

I can't reproduce this problem - maybe there is something more subtle about the required path. I have made a fix to make it a bit more friendly for non-ascii characters - see if it helps.

IPv6 commented 1 year ago

crash depends on path characters - some non-askii paths not causing it, but some do. so its kind of floating.

Thank you very much, will test with my projects soon. Happy new year, BTW!

IPv6 commented 1 year ago

@hughsando Seems to work now - without any problems so far! Tnx!