From 40a7fc9c57927e539f9ef74b867d5ead22dfe41a Mon Sep 17 00:00:00 2001 From: Ivan Mogilko Date: Tue, 11 Jul 2023 00:48:35 +0300 Subject: [PATCH] Editor: fixed conversion of the script names --- Editor/AGS.Native/NativeMethods.cpp | 10 ++++++++++ Editor/AGS.Native/NativeUtils.h | 1 + Editor/AGS.Native/ScriptCompiler.cpp | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Editor/AGS.Native/NativeMethods.cpp b/Editor/AGS.Native/NativeMethods.cpp index 050cdecf871..328b0ab4697 100644 --- a/Editor/AGS.Native/NativeMethods.cpp +++ b/Editor/AGS.Native/NativeMethods.cpp @@ -129,6 +129,16 @@ AGSString TextHelper::ConvertASCII(System::String^ clr_str) return str; } +std::string TextHelper::ConvertASCIIToStd(System::String^ clr_str) +{ + if (clr_str == nullptr) + return std::string(); + char* stringPointer = (char*)Marshal::StringToHGlobalAnsi(clr_str).ToPointer(); + std::string str = stringPointer; + Marshal::FreeHGlobal(IntPtr(stringPointer)); + return str; +} + void TextHelper::ConvertASCIIToArray(System::String^ clr_str, char *buf, size_t buf_len) { char* stringPointer = (char*)Marshal::StringToHGlobalAnsi(clr_str).ToPointer(); diff --git a/Editor/AGS.Native/NativeUtils.h b/Editor/AGS.Native/NativeUtils.h index e80a8228cc7..b867c08eb62 100644 --- a/Editor/AGS.Native/NativeUtils.h +++ b/Editor/AGS.Native/NativeUtils.h @@ -60,6 +60,7 @@ namespace TextHelper // Convert ASCII managed text to native string; // this is for symbol names of variables, functions and alike AGSString ConvertASCII(System::String^ clr_str); + std::string ConvertASCIIToStd(System::String^ clr_str); void ConvertASCIIToArray(System::String^ clr_str, char *buf, size_t buf_len); // Convert managed text to native string, forcing ASCII and testing for unknown chars // TODO: fix it uses and replace with ConvertUTF8ToArray diff --git a/Editor/AGS.Native/ScriptCompiler.cpp b/Editor/AGS.Native/ScriptCompiler.cpp index 717361d3301..1742ca1966b 100644 --- a/Editor/AGS.Native/ScriptCompiler.cpp +++ b/Editor/AGS.Native/ScriptCompiler.cpp @@ -76,7 +76,7 @@ namespace AGS AGS::MessageHandler mh; std::string mainScript = tcv->ConvertToStd(all_the_script); - std::string mainScriptName = tcv->ConvertToStd(script->FileName); + std::string mainScriptName = TextHelper::ConvertASCIIToStd(script->FileName); cc_script.reset(ccCompileText2(mainScript, mainScriptName, cc_options, mh)); auto compiler_messages = mh.GetMessages(); @@ -134,7 +134,7 @@ namespace AGS if (compile_error == nullptr) { mainScript = tcv->Convert(preProcessedScripts[preProcessedScripts->Length - 1]); - mainScriptName = tcv->Convert(script->FileName); + mainScriptName = TextHelper::ConvertASCII(script->FileName); cc_script.reset(ccCompileText(mainScript.GetCStr(), mainScriptName.GetCStr())); if (!cc_script || cc_has_error()) {