Game crashes when quit as a listen server

Hi all, as the title says, my code somehow crashes when exiting the game as a server.
Here is the code:

Error        LogWindows                === Critical error: ===
Error        LogWindows                Fatal error!
Error        LogWindows                Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x0000000000000368
Error        LogWindows                [Callstack] 0x00007ffe4fb4831a UE4Editor-Grounders.dll!AGroundersPlayerState::GetIsGrounder() [D:\Unreal Source Projects\GroundersGame\Source\Grounders\Private\Player\GroundersPlayerState.cpp:31]
Error        LogWindows                [Callstack] 0x0000027cfead0800 UnknownFunction []
Error        LogWindows                [Callstack] 0x0000000000000001 UnknownFunction []
Error        LogWindows                [Callstack] 0x0000027c940d0c30 UnknownFunction []
Error        LogWindows                [Callstack] 0x0000027cfead0800 UnknownFunction []

Please ask for any more info, any help is appreciated.

well what is the line of code on GroundersPlayerState.cpp line 31?

Right now I have

bool AGroundersPlayerState::GetIsGrounder()
{
	AGroundersCharacter* Char = GetPawn<AGroundersCharacter>();
	if (Char)
	{
		return bIsGrounder;
	} else
	{
		return false;
	}
}

(Line 31 is AGroundersCharacter* Char = GetPawn<AGroundersCharacter>();, but assigning a variable without using it shouldn’t crash it, right? I do check before using)

But it almost doesn’t matter, I tried it with

int32 x = 15;
UE_LOG(LogTemp, Warning, TEXT("%i"), x);

and that doesn’t work either, the error line was int32 x = 15;

My guess is that the entire AGroundersPlayerState is null and the stack trace is lying. I would take a backup of the project, then remove all references to GetIsGrounder() and see what happens. Then I would re-add every reference 1 by 1 until it crashes again to see which specific call is the issue.

1 Like

Sure, I’ll try that and get back to you.

Probably something else is trying to access that PlayerState after the game has already invalidated it. I’d run it in debugger, and get a good call stack on it. Whatever is calling that shouldn’t be calling it if the game is terminating.

1 Like

I’ll try that as well, thanks

Found it. I’m calling it in LogOut on the gamemode. It’s understanable but I was under the impression that the player’s objects are destroyed after that code. Guess I’ll have to find something else to run that. (Super::LogOut is run at the end of my override btw)

I’ve changed the code so that if it is the server disconnecting (clients disconnecting works fine) it doesn’t run the code and instead disconnects all clients first. Many thanks

1 Like

Glad to hear