Session hosting assertion failed

Hi,
I am trying to get the multiplayer hosting session working working with c++, but whenever I get to the bIsLAN session setting I get this line:
Assertion failed: IsValid() [File:E:\Engines\UnrealEngine\Engine\Source\Runtime\Core\Public\Templates/SharedPointer.h] [Line: 835]

.hpp:

TSharedPtr<class FOnlineSessionSettings> sessionSettings;

.cpp:

IOnlineSubsystem* const onlineSub = IOnlineSubsystem::Get();	
	if (onlineSub != nullptr) {
		//get session interface, so we can call the "create session" function		
		IOnlineSessionPtr sessions = onlineSub->GetSessionInterface();

		if (sessions.IsValid() && userId.IsValid()) {
			//Fill in session settings --sessionSettings->Set(...) for more settings--
			sessionSettings->bIsLANMatch = true;
			sessionSettings->bUsesPresence = bIsPresence;
			sessionSettings->NumPublicConnections = maxPlayers;
			sessionSettings->NumPrivateConnections = 0;
			sessionSettings->bAllowInvites = true;
			sessionSettings->bAllowJoinInProgress = true;
			sessionSettings->bShouldAdvertise = true;
			sessionSettings->bAllowJoinViaPresence = true;
			sessionSettings->bAllowJoinViaPresenceFriendsOnly = false;

			sessionSettings->Set(SETTING_MAPNAME, FString("Lobby"), EOnlineDataAdvertisementType::ViaOnlineService);

Any Help would be appreciated!

sessionSettings is null, where do you setting it? TSharedPtr is pointer so you need to set it first to use it.

But i don’t really see point of using pointer here as this class only hold settings and it’s not UObject, so just statically declare it like this:

class FOnlineSessionSettings sessionSettings;

This will make make this embeded with class and data will go away with the class you writing code in, no need to memory manage it sepretly.

Thank you,

So I added SessionSettings = MakeShareable(new FOnlineSessionSettings());
Before I set the session settings, but now my game gets a Fatal error, and the logs doesn’t show( or I cannot see) what the problem is.

All I know of debugging is it happens on This Line
return Sessions->CreateSession(*userId, sessionName, *sessionSettings);

Can you provide full stack? install engine source and debug symbols if you don’t have it will show function calls inside the enigne code, so we will know exacly where it crashes. If you have crahs without info in log, that means you have a hard crash a error in CPU machine code and OS closes application without UE4 having any chance to react. The crashes with log are once that UE4 predicts (or rether assumes that perticilar state will cause hard crash that as you can see is harder to debug)

The way it is now it look ok to me, but if it’s still related to SessionSettings try static decleration as i said. note that you converting back to data anyway with * operator, so really there no point of dynamic deceleration of it and keeping it in pointer. Is there perticlar reason why you doing so?

bool ULabyrinthInstance::hostSession(TSharedPtr userId, FName sessionName, bool bIsLan, bool bIsPresence, int32 maxPlayers) {
//Get online subsystem to work
IOnlineSubsystem* const onlineSub = IOnlineSubsystem::Get();
if (onlineSub != nullptr) {
//get session interface, so we can call the “create session” function
IOnlineSessionPtr sessions = onlineSub->GetSessionInterface();

		if (sessions.IsValid() && userId.IsValid()) {
			//Fill in session settings --sessionSettings->Set(...) for more settings--
			//sessionSettings = MakeShareable(new FOnlineSessionSettings());
			sessionSettings.bIsLANMatch = bIsLan;			
			sessionSettings.bUsesPresence = bIsPresence;
			sessionSettings.NumPublicConnections = maxPlayers;
			sessionSettings.NumPrivateConnections = 0;
			sessionSettings.bAllowInvites = true;
			sessionSettings.bAllowJoinInProgress = true;
			sessionSettings.bShouldAdvertise = true;
			sessionSettings.bAllowJoinViaPresence = true;
			sessionSettings.bAllowJoinViaPresenceFriendsOnly = false;

			sessionSettings.Set(SETTING_MAPNAME, FString("Lobby"), EOnlineDataAdvertisementType::ViaOnlineService);

			//set delegate to handle session interface
			onCreateSessionCompleteDelegateHandle = sessions->AddOnCreateSessionCompleteDelegate_Handle(onCreateSessionCompleteDelegate);

			//delegate is called when complete (can be unsuccessful)
			return sessions->CreateSession(*userId, sessionName, sessionSettings);
		}
	}
	else
	{
		UE_LOG(sessionLog, Error, TEXT("NO SUBSYSTEM FOUND"));
	}
	return false;
}

I removed the pointer, and the crash still happens.
It pops up a window that says ‘fatal crash’ and that’s all.
I installed via source code and the exact crash happens on line:
return sessions->CreateSession(*userId, sessionName, sessionSettings);

I used a pointer, because the documentation of IOnlineSession::CreateSession uses the address of the session settings, did not know I could declare it statically.