Crash on Exit (Custom FEditorViewportClient): EditorModeManager.cpp (Line 727)

Context

Error

When exiting the editor, there is a crash in EditorModeManager.cpp on line 727:

InMode->Exit();

Cause

On exiting the engine, the custom FEditorViewportClient is being cleaned up AFTER FEditorModeTools is being cleaned up, which FEditorViewportClient relies on in its destructor.

Fix

Added FShadersource_TextureToolsModule::OnEditorClose function to FCoreDelegates::OnEnginePreExit to clean up the SharedPtr and trigger the destructors BEFORE the FEditorModeTools is cleaned up.

void FShadersource_TextureToolsModule::StartupModule()
{
	//...
	
	FCoreDelegates::OnEnginePreExit.AddRaw(this, &FShadersource_TextureToolsModule::OnEditorClose);
}

void FShadersource_TextureToolsModule::ShutdownModule()
{
	FCoreDelegates::OnEnginePreExit.RemoveAll(this);
	
	//...
}

void FShadersource_TextureToolsModule::OnEditorClose()
{
	if (ToolWidget.IsValid())
	{
		ToolWidget.Reset();
	}
}

Last updated