ElgEditorScripting icon indicating copy to clipboard operation
ElgEditorScripting copied to clipboard

Crash when opening animation blueprint

Open iznaut opened this issue 3 years ago • 1 comments

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

iznaut avatar Jan 05 '23 17:01 iznaut

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);
	}
}

igagnidze avatar Feb 13 '24 13:02 igagnidze