Hello when selecting items by clicking on them in a STileView widget I get a crash on line 267 of STableRow.h The error is Access violation reading location… This line triggers the error when accessing MyItem.
OwnerWidget->Private_SetItemSelection( *MyItem, true, true );
The tileview widget displays items fine and the actors are alive in the game it just selecting that causes the error. Not sure what im doing wrong or if i can use TWeakObjectPtr with STileView or what? Hopefully its a simple mistake on my part
Here is a simplified Widget that is basically what im doing. The TArray> comes from another class and gets copied into the member TArray Items of the widget.
Code:
class SGroupControllerWidget : public SCompoundWidget
{
SLATE_BEGIN_ARGS(SGroupControllerWidget)
{}
SLATE_ARGUMENT(TWeakObjectPtr<AGameHUD>, OwnerHUD)
SLATE_END_ARGS()
public:
void Construct(const FArguments& InArgs);
void RefreshList();
private:
TSharedPtr<STileView<TWeakObjectPtr<AActor>>> TileViewWidget;
TArray<TWeakObjectPtr<AActor>> Items;
TSharedRef<ITableRow> OnGenerateTile(TWeakObjectPtr<AActor> Item, const TSharedRef<STableViewBase>& OwnerTable);
};
.cpp
void SGroupControllerWidget::Construct(const FArguments& InArgs)
{
OwnerHUD = InArgs._OwnerHUD;
this->GroupController = OwnerHUD->GetGroupController();
this->GroupController->OnControlGroupChanged.AddRaw(this, &SGroupControllerWidget::RefreshList);
this->UIResources = FUIResources::Get();
this->HUDStyle = &this->UIResources->GetWidgetStyle<FHUDStyle>("/Styles/HUDStyle");
ChildSlot
.VAlign(VAlign_Fill)
.HAlign(HAlign_Fill)
[
SNew(SBox)
.Padding(FMargin(30.0f, 10.0f))
.WidthOverride(1000.0f)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
[
SAssignNew(this->TileViewWidget, STileView<TWeakObjectPtr<AActor>>)
.ListItemsSource(&Items)
.OnGenerateTile(this, &SGroupControllerWidget::OnGenerateTile)
]
] // end horizontal slot
] //end border
]; //end childslot
}
void SGroupControllerWidget::RefreshList()
{
if (this->GroupController.IsValid() && this->TileViewWidget.IsValid())
{
TArray<TWeakObjectPtr<AActor>>* Actors = this->GroupController->GetSelectedGroup();
if (Actors)
{
this->Items = *(Actors);
}
else
{
this->Items.Empty();
}
this->TileViewWidget->RequestListRefresh();
}
}
TSharedRef<ITableRow> SGroupControllerWidget::OnGenerateTile(TWeakObjectPtr<AActor> Item, const TSharedRef<STableViewBase>& OwnerTable)
{
// just a test method for demonstration purposes.
ABaseCharacter* Character = Cast<ABaseCharacter>(Item.Get());
if (Character)
{
return SNew(STableRow< TSharedPtr<SWidget> >, OwnerTable)
[
SNew(STextBlock).Text(TAttribute<FString>(FString::FromInt(Character->GetHealth())))
];
}
else
{
return SNew(STableRow< TSharedPtr<SWidget> >, OwnerTable)
[
SNew(STextBlock).Text(TAttribute<FString>(TEXT("UNKNOWN Type")))
];
}
}