EXCEPTION_ACCESS_VIOLATION when using LoadSynchronous()

Hey guys, I am getting an error


EXCEPTION_ACCESS_VIOLATION reading address 0x00000000

when calling LoadSynchronous() on a TSoftClassPtr.

Here is the TSoftClassPtr:


TSoftClassPtr<AController> SidekickAIControllerClass = TSoftClassPtr<AController>(FSoftObjectPath(TEXT("Class'/Game/MultiplayerTemplate/Blueprints/Gameplay/AI/SidekickAI/BP_AICSidekick.BP_AICSidekick_C'")));

And here is the line that calls the LoadSynchronous:


Controller->SidekickAIControllerClass.LoadSynchronous();

I’ve made sure that the path in the TSoftObjectPath is correct… The code is being run in a server RPC if that makes any difference. Does anyone know what might be happening here?

“Controller” is null.

@Jambax unfortunately I don’t think that’s the case as I do a check on controller first to make sure it’s not nullptr.

All of this happens, and then the game errors out specifically when I try to access SidekickAIControllerClass.



if (Controller)
{ Controller->Sidekick->GetController()->UnPossess();
UClass* Example = Controller->SidekickAIControllerClass;
Controller->Sidekick->AIControllerClass = Controller->SidekickAIControllerClass.LoadSynchronous();
Controller->Sidekick->SpawnDefaultController();
 
  }


I’m really thinking this is a replication related error as this is the output of the crash. It mentions OnlineSubsystemUtils, and line 86 is the line where it tries to set AIControllerClass to SidekickAIControllerClass:



Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000000

UE4Editor_Engine
UE4Editor_MultiplayerTemplate!ATrainerController::SpawnSidekick_Implementation() [A:\Project Tall Grass\Test Multiplayer\Source\MultiplayerTemplate\Trainer\TrainerController.cpp:86]
UE4Editor_MultiplayerTemplate!ATrainerController::execSpawnSidekick() [A:\Project Tall Grass\Test Multiplayer\Intermediate\Build\Win64\UE4Editor\Inc\MultiplayerTemplate\TrainerController.gen.cpp:44]
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_OnlineSubsystemUtils
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor
UE4Editor
UE4Editor
UE4Editor
UE4Editor
kernel32
ntdll


Is there anything else I could check?

Ultimately the crash you are getting is caused by dereferencing a nullptr.

The snippet you posted above has a lot of cases of dereferencing pointers without checking they are valid first. Controller might not be null, but what about everything else?