Skip to content

Commit 31fd6f6

Browse files
authored
Fix crash when OnMapOpened delegate fires after SLevelEditorFlow destruction (#362)
The SLevelEditorFlow widget subscribes to FEditorDelegates::OnMapOpened using AddRaw, but never unsubscribes. When a map is loaded and the widget has been destroyed, the delegate fires on a stale pointer causing an access violation. Fix: Store the delegate handle and remove it in the destructor.
1 parent 31b4d49 commit 31fd6f6

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

Source/FlowEditor/Private/Utils/SLevelEditorFlow.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
void SLevelEditorFlow::Construct(const FArguments& InArgs)
1515
{
1616
CreateFlowWidget();
17-
FEditorDelegates::OnMapOpened.AddRaw(this, &SLevelEditorFlow::OnMapOpened);
17+
OnMapOpenedHandle = FEditorDelegates::OnMapOpened.AddRaw(this, &SLevelEditorFlow::OnMapOpened);
18+
}
19+
20+
SLevelEditorFlow::~SLevelEditorFlow()
21+
{
22+
FEditorDelegates::OnMapOpened.Remove(OnMapOpenedHandle);
1823
}
1924

2025
void SLevelEditorFlow::OnMapOpened(const FString& Filename, bool bAsTemplate)

Source/FlowEditor/Public/Utils/SLevelEditorFlow.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class FLOWEDITOR_API SLevelEditorFlow : public SCompoundWidget
1414

1515
void Construct(const FArguments& InArgs);
1616

17+
~SLevelEditorFlow();
18+
1719
protected:
1820
void OnMapOpened(const FString& Filename, bool bAsTemplate);
1921
void CreateFlowWidget();
@@ -24,4 +26,5 @@ class FLOWEDITOR_API SLevelEditorFlow : public SCompoundWidget
2426
static class UFlowComponent* FindFlowComponent();
2527

2628
FString FlowAssetPath;
29+
FDelegateHandle OnMapOpenedHandle;
2730
};

0 commit comments

Comments
 (0)