From a067cbd9092cf67ce540fda01da30974bb427a41 Mon Sep 17 00:00:00 2001 From: Jenner Date: Fri, 24 May 2024 01:16:24 +0800 Subject: [PATCH 1/2] [Fix] Exception is thrown when executing the `Generator IntelliSense` command. --- .../UnLuaEditor/Private/UnLuaIntelliSense.cpp | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Plugins/UnLua/Source/UnLuaEditor/Private/UnLuaIntelliSense.cpp b/Plugins/UnLua/Source/UnLuaEditor/Private/UnLuaIntelliSense.cpp index 7e132e2d..8641a60d 100644 --- a/Plugins/UnLua/Source/UnLuaEditor/Private/UnLuaIntelliSense.cpp +++ b/Plugins/UnLua/Source/UnLuaEditor/Private/UnLuaIntelliSense.cpp @@ -111,11 +111,11 @@ namespace UnLua Ret += FString::Printf(TEXT("local %s = {}\r\n"), *EscapeSymbolName(TypeName)); // exported functions - const auto Exported = GetExportedReflectedClasses().Find(TypeName); - if (Exported) + if (GetExportedReflectedClasses().Find(TypeName)) { + const auto Exported = GetExportedReflectedClasses()[TypeName]; TArray ExportedFunctions; - (*Exported)->GetFunctions(ExportedFunctions); + Exported->GetFunctions(ExportedFunctions); for (const auto Function : ExportedFunctions) Function->GenerateIntelliSense(Ret); } @@ -174,14 +174,17 @@ namespace UnLua } // exported functions - const auto Exported = GetExportedReflectedClasses().Find(TypeName); - if (Exported) + if (GetExportedReflectedClasses().Find(TypeName)) { - TArray ExportedFunctions; - (*Exported)->GetFunctions(ExportedFunctions); - for (const auto Function : ExportedFunctions) - Function->GenerateIntelliSense(Ret); + if (const auto Exported = GetExportedReflectedClasses()[TypeName]) + { + TArray ExportedFunctions; + Exported->GetFunctions(ExportedFunctions); + for (const auto Function : ExportedFunctions) + Function->GenerateIntelliSense(Ret); + } } + return Ret; } From de7e28efff909200a74108d8f71bea8786572bde Mon Sep 17 00:00:00 2001 From: Jenner Date: Sun, 26 May 2024 21:45:16 +0800 Subject: [PATCH 2/2] [Fix] Extend the lifetime of the copied value of `ReflectedClasses` --- .../UnLuaEditor/Private/UnLuaIntelliSense.cpp | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Plugins/UnLua/Source/UnLuaEditor/Private/UnLuaIntelliSense.cpp b/Plugins/UnLua/Source/UnLuaEditor/Private/UnLuaIntelliSense.cpp index 8641a60d..c4c1a672 100644 --- a/Plugins/UnLua/Source/UnLuaEditor/Private/UnLuaIntelliSense.cpp +++ b/Plugins/UnLua/Source/UnLuaEditor/Private/UnLuaIntelliSense.cpp @@ -111,11 +111,12 @@ namespace UnLua Ret += FString::Printf(TEXT("local %s = {}\r\n"), *EscapeSymbolName(TypeName)); // exported functions - if (GetExportedReflectedClasses().Find(TypeName)) + const auto& ExportedReflectedClasses = GetExportedReflectedClasses(); + const auto Exported = ExportedReflectedClasses.Find(TypeName); + if (Exported) { - const auto Exported = GetExportedReflectedClasses()[TypeName]; TArray ExportedFunctions; - Exported->GetFunctions(ExportedFunctions); + (*Exported)->GetFunctions(ExportedFunctions); for (const auto Function : ExportedFunctions) Function->GenerateIntelliSense(Ret); } @@ -174,17 +175,15 @@ namespace UnLua } // exported functions - if (GetExportedReflectedClasses().Find(TypeName)) + const auto& ExportedReflectedClasses = GetExportedReflectedClasses(); + const auto Exported = ExportedReflectedClasses.Find(TypeName); + if (Exported) { - if (const auto Exported = GetExportedReflectedClasses()[TypeName]) - { - TArray ExportedFunctions; - Exported->GetFunctions(ExportedFunctions); - for (const auto Function : ExportedFunctions) - Function->GenerateIntelliSense(Ret); - } + TArray ExportedFunctions; + (*Exported)->GetFunctions(ExportedFunctions); + for (const auto Function : ExportedFunctions) + Function->GenerateIntelliSense(Ret); } - return Ret; }