Skip to content

Commit

Permalink
Editor: fixed conversion of the script names
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Jul 10, 2023
1 parent 269f7f2 commit 40a7fc9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Editor/AGS.Native/NativeMethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions Editor/AGS.Native/NativeUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Editor/AGS.Native/ScriptCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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())
{
Expand Down

0 comments on commit 40a7fc9

Please sign in to comment.