Unreal Crash when loadMap by CPP
I am developing a feature to allow user to open a map from Editor Utilities Widget.
Here is my code:
bool UContentToolsEditorBlueprintLibrary::OpenMap()
{
FString LevelPath = "/Game/Test/Maps/Demos/VTAR/Level_Instances/TestMap/TestMap.TestMap";
if (ULevelEditorSubsystem* LevelEditorSubsystem = GEditor->GetEditorSubsystem<ULevelEditorSubsystem>())
{
if (FEditorModeTools* ModeManager = LevelEditorSubsystem->GetLevelEditorModeManager())
{
ModeManager->DeactivateAllModes();
}
}
if (!GIsDemoMode)
{
// If there are any unsaved changes to the current level, see if the user wants to save those first.
bool bPromptUserToSave = true;
bool bSaveMapPackages = true;
bool bSaveContentPackages = true;
if (FEditorFileUtils::SaveDirtyPackages(bPromptUserToSave, bSaveMapPackages, bSaveContentPackages) == false)
{
return false;
}
}
const bool bLoadAsTemplate = false;
const bool bShowProgress = true;
FEditorFileUtils::LoadMap(LevelPath, bLoadAsTemplate, bShowProgress);
return true;
}```
If i exec the code with a simple level, it works well,
but when i exec the code with a special level (Have some sub levels), the unreal will crash, and it looks like the memory is leaking, here is the outlog before crash (Sooo sorry that i have to remove my company name):
![image|690x175](upload://ejxP4q597vBqT1oUjctBZ1istDb.png)
Can anyone help please!