C++ GetComponentsBoundingBox() returns access violation

Hello!
I am developing a multiplayer game, in which my GameMode calls a method from a spawn area, to obtain a random point in it. I call this method from my PostLogin method.

In the returnRandomPoint function I cannot access the GetComponentsBoundingBox, because my game crashes with an access violation.
It crashes in this if. (The if was just for testing purpose)

if (GetComponentsBoundingBox().Min.X == NULL)
{
	UE_LOG(LogTemp, Warning, TEXT("Test"));
}

Do I have to declare the BoundingBox in the constructor or somewhere? Because all I have in my constructor is this:

PrimaryActorTick.bCanEverTick = true;
 UBoxComponent* comp = CreateDefaultSubobject<UBoxComponent>(TEXT("test"));
 RootComponent=comp;

This is the error I get:
MachineId:13D666B54D30E7423C3F99BE11422981
EpicAccountId:

Access violation - code c0000005 (first/second chance not available)

UE4Editor_SchulCS_4401!ASpawnArea::returnRandomPoint() [c:\users\user\documents\unreal projects\schulcs\source\schulcs\spawnarea.cpp:40]
UE4Editor_SchulCS_4401!ASchulCSGameMode::spawnPlayers() [c:\users\user\documents\unreal projects\schulcs\source\schulcs\schulcsgamemode.cpp:110]
UE4Editor_SchulCS_4401!ASchulCSGameMode::PostLogin() [c:\users\user\documents\unreal projects\schulcs\source\schulcs\schulcsgamemode.cpp:54]
UE4Editor_Engine!UWorld::SpawnPlayActor() [d:\build++ue4+release-4.13+compile\sync\engine\source\runtime\engine\private\levelactor.cpp:710]
UE4Editor_Engine!ULocalPlayer::SpawnPlayActor() [d:\build++ue4+release-4.13+compile\sync\engine\source\runtime\engine\private\localplayer.cpp:228]
UE4Editor_Engine!UEngine::LoadMap() [d:\build++ue4+release-4.13+compile\sync\engine\source\runtime\engine\private\unrealengine.cpp:10019]
UE4Editor_Engine!UEngine::Browse() [d:\build++ue4+release-4.13+compile\sync\engine\source\runtime\engine\private\unrealengine.cpp:9126]
UE4Editor_Engine!UGameInstance::StartGameInstance() [d:\build++ue4+release-4.13+compile\sync\engine\source\runtime\engine\private\gameinstance.cpp:358]
UE4Editor!FEngineLoop::Init() [d:\build++ue4+release-4.13+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:2361]
UE4Editor!GuardedMain() [d:\build++ue4+release-4.13+compile\sync\engine\source\runtime\launch\private\launch.cpp:143]
UE4Editor!GuardedMainWrapper() [d:\build++ue4+release-4.13+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() [d:\build++ue4+release-4.13+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:202]
UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:264]
kernel32
ntdll

Thank you in advance for your help!

You are trying to call GetComponentsBoundingBox() on null actor pointer or somewhere in unavailable memory.
This function can’t return null pointer, but it can try access ASpawnArea from which it was called by address that not legit.
For example somewhere in a code ASpawnArea * spawnArea for some reasons equals null or even unintialized (memory leftover). Next call is being executed spawnArea->returnRandomPoint(), stack will be modified, thread will jump at function begin address (it always exists), function will be called fine even though spawnArea is null. But as soon as class methods is called this will be a little different: method will actually be compiled as “this->GetComponentsBoundingBox()”. “this” in current context is null, method will be called, but if it will try to get class data then address violation exception will be triggered.
I suppose somewhere in line 110 in schulcsgamemode.cpp returnRandomPoint() has been executed on null or trash pointer.

But why is it a trash pointer?
I placed two spawn areas into the map and in the beginplay function of the gamemode I am referencing them to two pointers. So it should be a valid pointer, or am I missing something?

It depends on how you referencing them.
If you are somehow finding them, then maybe (very maybe) level is in the state, when actors aren’t spawned yet or not spawned completely. I mean from call stack I see that level is only began loading, not all actors can be loaded. PostLogin() I think called before actual level load, but I’am not sure.
By the way you can always use breakpoints and step-by-step execution, why don’t you check 110-th line values? :smiley:
Or can you show code above 110-th line? Or at least how you obtaining references.

Ok, thank you for the help!