ElgSoft / ElgEditorScripting

ElgEditorScripting is an Unreal Engine 5 editor only plugin created to extend the possibilities of Editor Utility Widgets.
MIT License
201 stars 34 forks source link

Crash when opening animation blueprint #8

Open iznaut opened 1 year ago

iznaut commented 1 year ago

When opening an animation blueprint with this plugin enabled, UE4 will crash.

UE4Editor_ElgEditorScripting!UElgEditorContext_LevelEditor::HandleEditorModeEnter() [E:\P4NoGoblin\NG3Game\Plugins\ElgEditorScripting\Source\ElgEditorScripting\Private\EditorContexts\ElgEditorContext_LevelEditor.cpp:203]

The third line of this function in ElgEditorContext_LevelEditor.cpp was the problem:

void UElgEditorContext_LevelEditor::HandleEditorModeEnter(const FEditorModeID& ModeID)
{   
    FText oldName = CurrentEditorMode;
    FEdMode* mode = GLevelEditorModeTools().GetActiveMode(ModeID);
    CurrentEditorMode = mode->GetModeInfo().Name;
    OnEnterMode.Broadcast(CurrentEditorMode);
    if (!oldName.EqualTo(CurrentEditorMode)) {
        OnEditorModeChanged.Broadcast(CurrentEditorMode);
    }
}

My colleague was able to fix it by simply doing a check to make sure mode != NULL, so there's a workaround, but I thought I would report here so it could be properly fixed in the source.

top of the callstack was FName triggering an access violation, the crash is on the line where we're assigning a FName from a function that can return null, so I did a quick null check on the function before doing anything else

igagnidze commented 8 months ago

Thx for this, I got the 4.27 version and this was happening there too. It needs to be handled for both HandleEditorModeEnter and HandleEditorModeExit or the crash happens when closing animbp (and potentially some other editors like Niagara or Cascade) as well.

Here's the code if anyone wants to just copy/paste it (replace the existing code)

void UElgEditorContext_LevelEditor::HandleEditorModeEnter(const FEditorModeID& ModeID)
{   
    FText oldName = CurrentEditorMode;
    FEdMode* mode = GLevelEditorModeTools().GetActiveMode(ModeID);
    if(mode != nullptr){
        CurrentEditorMode = mode->GetModeInfo().Name;
        OnEnterMode.Broadcast(CurrentEditorMode);
        if (!oldName.EqualTo(CurrentEditorMode)) {
            OnEditorModeChanged.Broadcast(CurrentEditorMode);
        }
    }
}

void UElgEditorContext_LevelEditor::HandleEditorModeExit(const FEditorModeID& ModeID)
{
    FEdMode* mode = GLevelEditorModeTools().GetActiveMode(ModeID);
    if(mode != nullptr){
        OnExitMode.Broadcast(mode->GetModeInfo().Name);
    }
}