Utility widget list view causing crash between map loads.

I have encountered an issue with a utility panel using a listview in a blueprint utility widget.

I believe I’ve definitely narrowed it down to the listview.

I have a utility widget panel that populates a list view if any specific actors are present in the level (it’s actually specific to children of an actor that is selected for editing in the panel.) Everything about it is working great. I’m subscribing to OnDestroys so that I can appropriately rebuild the list view if any of its item objects are unexpectedly removed from the level.

However, if I load a new level while the list view widget has any entries, the editor crashes on the following error:

[2019.06.24-20.02.43:984] 56]Cmd: MAP LOAD FILE="F:/[project]/Content/Levels/Level_MainMenu.umap" TEMPLATE=0 SHOWPROGRESS=1 FEATURELEVEL=3
[2019.06.24-20.02.43:985] 56]LightingResults: New page: Lighting Build
[2019.06.24-20.02.43:985] 56]LoadErrors: New page: Loading map: Level_MainMenu.umap
[2019.06.24-20.02.43:987] 56]MapCheck: New page: Map Check
[2019.06.24-20.02.43:987] 56]LightingResults: New page: Lighting Build
[2019.06.24-20.02.44:026] 56]LogUObjectHash: Compacting FUObjectHashTables data took   3.23ms
[2019.06.24-20.02.44:830] 56]LogReferenceChain: (root) GCObjectReferencer /Engine/Transient.GCObjectReferencer_0::AddReferencedObjects()
[2019.06.24-20.02.44:830] 56]LogReferenceChain:  AKeyvent_C /Game/Levels/Level_TestLevelDesigner.Level_TestLevelDesigner:PersistentLevel.AKeyvent_C_0::AddReferencedObjects()
[2019.06.24-20.02.44:832] 56]LogReferenceChain:                Level /Game/Levels/Level_TestLevelDesigner.Level_TestLevelDesigner:PersistentLevel->Outer
[2019.06.24-20.02.44:833] 56]LogReferenceChain:                 World /Game/Levels/Level_TestLevelDesigner.Level_TestLevelDesigner
[2019.06.24-20.02.44:833] 56]LogReferenceChain:  
[2019.06.24-20.02.45:200] 56]LogOutputDevice: Warning:

Script Stack (0 frames):

[2019.06.24-20.02.45:200] 56]LogWindows: Windows GetLastError: The operation completed successfully. (0)
[2019.06.24-20.02.45:621] 56]LogWindows: Error: === Critical error: ===
[2019.06.24-20.02.45:621] 56]LogWindows: Error:
[2019.06.24-20.02.45:621] 56]LogWindows: Error: Fatal error: [File:D:\Build\++UE4\Sync\Engine\Source\Editor\UnrealEd\Private\EditorServer.cpp] [Line: 1971]
[2019.06.24-20.02.45:621] 56]LogWindows: Error: /Game/Levels/Level_TestLevelDesigner.Level_TestLevelDesigner still around while trying to load new map
[2019.06.24-20.02.45:621] 56]LogWindows: Error:    (Object is not currently rooted)

The trimmed portion walks the attachment hierarchy. I reproduced the crash in a very simple scene and distilled the error down to the simplest common logs.

This “AKeyvent” actor is spawned and attached to other controller actors in the level through a level design utility. When you select one of these controller actors, it populates a list of the AKeyvents attached to it.

If I load a new map while a controller actor with no AKeyvents attached to it, and thus, no list items, the editor proceeds fine. If 1 or more AKeyvent or any derivative classes are attached and entered into a list, the editor crashes.

The AKeyvent listview is a new feature for the level design utility, and this crash cropped up once the list came on line. The crash did NOT occur when we were manually adding AKeyvents to the levels for testing.

I tried subscribing to the editor context event of OnMapOpen to clear the list, as well as some other editor context events that seemed like they might be appropriate. OnMapOpen seemed the most appropriate since that seems to happen before the old map is unloaded.

I feel like there must be some best practice I am unaware of to simply reset the utility widget when a map change is occurring. Any advice would be great!

Just at a guess here - try to make sure you never store actual object references. Have each entry in the list widget correlate to a *soft *object reference. Then whenever you need to get info from the object or select it etc, then resolve the soft object reference inside a function and do your stuff there, so the actual object reference is only temporary. If resolving the soft object reference fails during one of these operations, then that is when you should probably repopulate the list.

Oddly enough I had the same issue pop up today. It was happening because I had a UPROPERTY(Transient) UObject* on an FAssetEditorToolkit which points to an actor in the current level. When changing levels, I got the same crash. I changed the pointer to a TWeakObjectPtr<UObject> and that solved the problem.

Unfortunately, this didn’t work. I continue to investigate.

Thanks for the advice, though.

[EDIT] I was responding to Spoondog, and hadn’t seen mjw18’s response. I am using blueprint and the new utility widgets. But I’ve been reading more and am going to see if I can’t fix this by binding to the list item’s (not the widget) destroy and try and release the object. I do this in other places to other references, but not this one, because usually I am just trying to keep the loaded level in sync with the widget, and have never had to worry about unloaded levels until now.