AsShared() error with SListView

I try to add a simple SListView with FString-content to a new window which I create with a plugin.
Unfortunately after two days searching in the UE4-sourcecode I still can’t get a window with a simple listview working.

Part where the SWidget is created which should be added to the window:

TSharedRef<SWidget> windowContent = SNew(SBox)
					SAssignNew(listView, SListView<TSharedPtr<FString>>)
					.OnGenerateRow(this, &FImportLayers::GeneratePresetListRow)


My OnGenerateRow-function:

TSharedRef<ITableRow> FImportLayers::GeneratePresetListRow(TSharedPtr<FString> InItem, const TSharedRef<STableViewBase>& OwnerTable)
		SNew(STableRow<TSharedPtr<FString>>, OwnerTable)

This is the crash error when the SWidget should be created:

Unknown exception - code 00000001 (first/second chance not available)

Assertion failed: SharedThis.Get() == this [File:XXX\UnrealEngine\Engine\Source\Runtime\Core\Public\Templates\SharedPointer.h] [Line: 1012] 

KERNELBASE + 37901 bytes
UE4Editor_Core!FOutputDeviceWindowsError::Serialize() + 292 bytes [XXX\unrealengine\engine\source\runtime\core\private\windows\windowsplatformoutputdevices.cpp:95]
UE4Editor_Core!FOutputDevice::Logf__VA() + 248 bytes [XXX\unrealengine\engine\source\runtime\core\private\misc\outputdevice.cpp:144]
UE4Editor_Core!FDebug::AssertFailed() + 1079 bytes [XXX\unrealengine\engine\source\runtime\core\private\misc\outputdevice.cpp:224]
UE4Editor_ImportLayers!TSharedFromThis<IDetailCustomization,0>::AsShared() + 120 bytes [XXX\unrealengine\engine\source\runtime\core\public\templates\sharedpointer.h:1016]

The header file to the main class:

    class FImportLayers : public IModuleInterface, public TSharedFromThis<FImportLayers>
    	TSharedRef<ITableRow> GeneratePresetListRow(TSharedPtr<FString> InItem, const TSharedRef<STableViewBase>& OwnerTable);
    	TSharedPtr<SListView<TSharedPtr<FString>>> listView;
    	TArray<TSharedPtr<FString>> presetList;

Do you have any idea why I get this crash? As far as I know I used exactly the same code like it is used in all the examples in the UE source.

Thanks for your help. :slight_smile:

EDIT: It’s not directly related with the SListView. Now I tried another way with a SButton. Adding the SButton works fine, until I try to add the onClicked-function. With the OnClicked-function I get the same crash again. So it seems to related to the Delegates. Right?

It’s solved, but just in case somebody else stumbles across this:

The problem can be easily solved by adding the complete slate graphics to an own class and inherit from TSharedFromThis. Just take a look in the UE source code.

Good catch; glad you were able to figure it out.

I looked at the code you posted, and I don’t think the listing includes the culprit line. In this case, you seem to be creating a delegate that does a SharedThis(this) in a class that does not support doing SharedThis(this) because it does not inherit from TSharedFromThis<>.

We almost always put handlers for UI delegates inside of widget classes. The most common pattern is to use an SCompoundWidget as a host for most of your logic and child widgets. All widgets provide TSharedFromThis<> out of the box, so you should be safe if you follow that pattern. We also usually begin all out native widget classes with the letter S to help drive home the point about them being Slate Widgets.

Thats exactly how I did it! :slight_smile: Thanks for your comment.

Hi! Can you paste your solution code here? Don`t know why, but I can’t get it to work :confused: