A user reported that UToolMenus::GenerateWidget will crash if UToolMenus::AddReferencedObject is called during the construction of a menu. Using the above in-code repro steps, I can repro this in a unit test.
I do not know of a repro in the editor but with this code
UToolMenu* ToolMenu = UToolMenus::Get()->RegisterMenu("MyMenu"); ToolMenu->AddDynamicSection("MyDynamicLegacySection", FNewToolMenuDelegateLegacy::CreateLambda([](FMenuBuilder& InBuilder, UToolMenu* InMenu) { TArray<UObject*> Array; FReferenceFinder Finder(Array); UToolMenus::AddReferencedObjects(UToolMenus::Get(), Finder); })); UToolMenus::Get()->GenerateWidget("MyMenu", FToolMenuContext());
you will get a crash in UToolMenus::GenerateWidget(UToolMenu*) at ToolMenus.cpp:2119 as shown below
else if (GeneratedMenu->MenuType == EMultiBoxType::Menu) { FMenuBuilder MenuBuilder(GeneratedMenu->bShouldCloseWindowAfterMenuSelection, GeneratedMenu->Context.CommandList, GeneratedMenu->Context.GetAllExtenders(), GeneratedMenu->bCloseSelfOnly, GeneratedMenu->StyleSet, GeneratedMenu->bSearchable, GeneratedMenu->MenuName); if (GeneratedMenu->StyleName != NAME_None) { MenuBuilder.SetStyle(GeneratedMenu->StyleSet, GeneratedMenu->StyleName); } MenuBuilder.SetExtendersEnabled(GeneratedMenu->bExtendersEnabled); PopulateMenuBuilder(MenuBuilder, GeneratedMenu); TSharedRef<SWidget> Result = MenuBuilder.MakeWidget(nullptr, GeneratedMenu->MaxHeight); >>>> GeneratedMenuWidget.Widget = Result; return Result; }
This crash happens because the GeneratedMenuWidget was destroyed by UToolMenus::AddReferencedObjects within the callstack of PopulateMenuBuilder two lines above the crash.
There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-201151 in the post.
0 |
Component | UE - Editor - Workflow Systems |
---|---|
Affects Versions | 5.4 |
Target Fix | 5.4 |
Fix Commit | 30042012 |
---|---|
Main Commit | 30042071 |
Created | Nov 24, 2023 |
---|---|
Resolved | Dec 1, 2023 |
Updated | Jan 19, 2024 |