FOnlineSessionSearchResult is invalid

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!

JoinGameMenu may be nullptr but you are using it without validating it in UMyGameInstance::OnFindServersComplete. Is it a UPROPERTY()?

The crash occurs in the JoinGameMenu class:

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x0000000000000000

UnrealEditor_MyProject_0217!UWULJoinSubMenu::RegisterServerEntry() [F:\UE Projects\MyProject\Source\MyProject\Private\WidgetUnderlays\WULJoinSubMenu.cpp:66]
UnrealEditor_MyProject_0217!UMyGameInstance::OnFindServersComplete() [F:\UE Projects\MyProject\Source\MyProject\Private\MyGameInstance.cpp:138]

Line 66:

NewEntry->PingText->SetText(FText::FromString(FString::FromInt(Ping)));
			NewEntry->PlayerCountText-

But the crash occurs in whichever of the variables I try to pass through first.

JoinGameMenu was marked as a UPROPERTY(). I tried removing that marking, along with any functions marked as UFUNCTIONS() that are called for this. I also added a null-check for JoinGameMenu before calling the function. But no luck, still get the same crash.

The only thing I can think of is that it may not like accessing an FOnlineSessionSearchResult outside of the GI class (or maybe inside a UserWidget). If that is true, then how could I pass information from a search result to a widget for user display?