I keep receiving a crash when I try to Find Sessions with the Online Subsystem (Null for my case now).
The cause of the crash is that the FOnlineSessionSearchResult is nullptr/invalid when I try to add some of its member variables to my Server Browser Widget (Session ID, Ping, Number of Connections) at the part where I Pass Values to the Server Entry.
Function where the crash happens:
void UWULJoinSubMenu::RegisterServerEntry(const int32 SearchResultIndex, const FString ServerName, const int32 CurrentPlayers, const int32 MaxPlayers, const int32 Ping)
{
//Create Widget for Server Entry
UWULServerEntry* NewEntry = CreateWidget<UWULServerEntry>(this, UWULServerEntry::StaticClass());
if (NewEntry)
{
//Null-Check Search Results
if (MyGameInstance->SearchSettingsPtr.IsValid() && MyGameInstance->SearchSettingsPtr->SearchResults[SearchResultIndex].IsValid())
{
//Set reference to array for Joining
NewEntry->SearchResultIndex = SearchResultIndex;
//Pass values to the Server Entry
NewEntry->PingText->SetText(FText::FromString(FString::FromInt(Ping)));
NewEntry->PlayerCountText->SetText(FText::FromString(FString::FromInt(CurrentPlayers) + "/" + FString::FromInt(MaxPlayers)));
NewEntry->ServerNameText->SetText(FText::FromString(ServerName));
//Set info for the new Widget and add to child
ServerList->AddChild(NewEntry);
}
else UE_LOG(LogTemp, Error, TEXT("Invalid Search Settings or Search Result"))
}
}
Where it’s called from my game instance:
void UMyGameInstance::OnFindServersComplete(bool Success)
{
UE_LOG(LogTemp, Error, TEXT("Browsing Complete"));
if (!Success || !SearchSettingsPtr.IsValid())
{
UE_LOG(LogTemp, Error, TEXT("Browsing not successful, or Search Settings no longer valid"));
return;
}
//Iterator for Index referencing purposes
int32 Itr = 0;
//Register each Server Entry to the Server Browser Widget
for (FOnlineSessionSearchResult SearchResult : SearchSettingsPtr->SearchResults)
{
if (SearchResult.IsValid())
{
UE_LOG(LogTemp, Error, TEXT("Attempting to Register Server Entry"));
JoinGameMenu->RegisterServerEntry(Itr, *SearchResult.GetSessionIdStr(), SearchResult.Session.NumOpenPublicConnections, SearchResult.Session.SessionSettings.NumPublicConnections, SearchResult.PingInMs);
Itr++;
}
}
}
I can’t really make sense of it, I have the Null-Checks to ensure that the crash doesn’t happen, both in GI and the JoinSubMenu UserWidget. From the logs, I see that at least one session is found.
Any idea what might be going on?
I appreciate the help!