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

### Context

* Project: [SHADERSOURCE: Texture Tools](https://docs.shadersource.io/assets-and-plugins/texture-tools)
* Engine Version: 5.4

### 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.

```cpp
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();
	}
}
```
