更新 Source/FLESHEditor/Private/FLESHEditorModule.cpp
This commit is contained in:
@@ -13,6 +13,9 @@ void FFLESHEditorModule::StartupModule()
|
|||||||
// This code will execute after your module is loaded into memory
|
// This code will execute after your module is loaded into memory
|
||||||
// The exact timing is specified in the .uplugin file per-module
|
// The exact timing is specified in the .uplugin file per-module
|
||||||
|
|
||||||
|
// Add try-catch block to prevent crashes during startup
|
||||||
|
try
|
||||||
|
{
|
||||||
// Initialize style
|
// Initialize style
|
||||||
FFLESHEditorStyle::Initialize();
|
FFLESHEditorStyle::Initialize();
|
||||||
FFLESHEditorStyle::ReloadTextures();
|
FFLESHEditorStyle::ReloadTextures();
|
||||||
@@ -24,7 +27,7 @@ void FFLESHEditorModule::StartupModule()
|
|||||||
PluginCommands = MakeShareable(new FUICommandList);
|
PluginCommands = MakeShareable(new FUICommandList);
|
||||||
PluginCommands->MapAction(
|
PluginCommands->MapAction(
|
||||||
FFLESHEditorCommands::Get().OpenFLESHEditor,
|
FFLESHEditorCommands::Get().OpenFLESHEditor,
|
||||||
FExecuteAction::CreateRaw(this, &FFLESHEditorModule::OpenFLESHEditor),
|
FExecuteAction::CreateRaw(this, &FFLESHEditorModule::OpenFLESHEditorCommand),
|
||||||
FCanExecuteAction());
|
FCanExecuteAction());
|
||||||
|
|
||||||
// Register editor menus
|
// Register editor menus
|
||||||
@@ -49,6 +52,15 @@ void FFLESHEditorModule::StartupModule()
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
UE_LOG(LogTemp, Error, TEXT("FLESH Editor module startup failed: %s"), UTF8_TO_TCHAR(e.what()));
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
UE_LOG(LogTemp, Error, TEXT("FLESH Editor module startup failed with unknown exception"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FFLESHEditorModule::ShutdownModule()
|
void FFLESHEditorModule::ShutdownModule()
|
||||||
{
|
{
|
||||||
@@ -63,10 +75,61 @@ void FFLESHEditorModule::ShutdownModule()
|
|||||||
UToolMenus::UnregisterOwner(this);
|
UToolMenus::UnregisterOwner(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FFLESHEditorModule::OpenFLESHEditor()
|
void FFLESHEditorModule::OpenFLESHEditorCommand()
|
||||||
{
|
{
|
||||||
// Open FLESH editor
|
// Open the editor with default parameters
|
||||||
FFLESHEditor::OpenEditor();
|
OpenFLESHEditor(EToolkitMode::Standalone, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FFLESHEditorModule::OpenFLESHEditor(const EToolkitMode::Type Mode, const TSharedPtr<IToolkitHost>& InitToolkitHost, UObject* ObjectToEdit)
|
||||||
|
{
|
||||||
|
// Add try-catch block to prevent crashes when opening editor
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Check if FLESH module is loaded
|
||||||
|
if (!FModuleManager::Get().IsModuleLoaded("FLESH"))
|
||||||
|
{
|
||||||
|
UE_LOG(LogTemp, Error, TEXT("Cannot open FLESH Editor: FLESH module is not loaded"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no object is provided, create a default object to edit
|
||||||
|
if (ObjectToEdit == nullptr)
|
||||||
|
{
|
||||||
|
// Try to find or create a dismemberment graph asset to edit
|
||||||
|
UClass* DismembermentGraphClass = FindObject<UClass>(nullptr, TEXT("/Script/FLESH.DismembermentGraphAsset"));
|
||||||
|
if (DismembermentGraphClass)
|
||||||
|
{
|
||||||
|
// Try to find an existing asset first
|
||||||
|
ObjectToEdit = FindObject<UObject>(nullptr, TEXT("DefaultDismembermentGraph"));
|
||||||
|
|
||||||
|
// If not found, create a temporary object
|
||||||
|
if (ObjectToEdit == nullptr)
|
||||||
|
{
|
||||||
|
ObjectToEdit = NewObject<UObject>(GetTransientPackage(), DismembermentGraphClass, TEXT("DefaultDismembermentGraph"));
|
||||||
|
ObjectToEdit->AddToRoot(); // Prevent garbage collection
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If we can't find the class, create a basic UObject
|
||||||
|
ObjectToEdit = NewObject<UObject>(GetTransientPackage(), UObject::StaticClass(), TEXT("DefaultFLESHObject"));
|
||||||
|
ObjectToEdit->AddToRoot(); // Prevent garbage collection
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new FLESH editor
|
||||||
|
TSharedRef<FFLESHEditor> NewFLESHEditor(new FFLESHEditor());
|
||||||
|
NewFLESHEditor->InitFLESHEditor(Mode, InitToolkitHost, ObjectToEdit);
|
||||||
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
UE_LOG(LogTemp, Error, TEXT("Failed to open FLESH Editor: %s"), UTF8_TO_TCHAR(e.what()));
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
UE_LOG(LogTemp, Error, TEXT("Failed to open FLESH Editor with unknown exception"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef LOCTEXT_NAMESPACE
|
#undef LOCTEXT_NAMESPACE
|
||||||
|
Reference in New Issue
Block a user