This problem has cost me the better part of two hours ans slowly it’s becoming infuriating, since I simply can’t find the source of the error.
I have a custom component written in C++ that manages an inventory. The initialisation of said inventory via an init method happens on the server as it should be. If I run the game as server everything works fine, but when I run it as a client on a dedicated server it immediately crashes after the init method has run. I checked the variables for nullptr and they all exist properly on client and server.
The created log file isn’t helping as it only tells the following:
[2017.06.27-19.56.50:679][213]LogWindows:Error: === Critical error: ===
[2017.06.27-19.56.50:679][213]LogWindows:Error:
[2017.06.27-19.56.50:679][213]LogWindows:Error: Fatal error!
[2017.06.27-19.56.50:679][213]LogWindows:Error:
[2017.06.27-19.56.50:679][213]LogWindows:Error: Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000008
This is the method in question:
UInventoryComponent::UInventoryComponent()
{
PrimaryComponentTick.bCanEverTick = true;
bReplicates = true;
}
void UInventoryComponent::Init_Implementation(int32 initialSize, const TArray<FInventoryItem>& initialItems)
{
if (this->GetOwnerRole() != ROLE_Authority)
{
UE_LOG(FantasyGeneral, Warning, TEXT("Remote tried to access authority function"));
return;
}
int32 actualSize = initialSize < initialItems.Num() ? initialItems.Num() : initialSize;
this->Size = actualSize;
this->Items.Init(FInventoryItem(), actualSize);
if (initialItems.Num() > 0)
{
for (int32 i = 0; i < initialItems.Num(); i++)
{
this->Items.Insert(initialItems[i], i);
}
}
this->OnInventoryItemsChanged.Broadcast();
}
The FInventoryItem struct is a simple data holding struct where every property is marked as UPROPERTY(), so it shouldn’t be causing any issues. I should add that every method I posted here runs fine, until the end of the Init method. After the ‘Broadcast()’ method call the game goes into the GENERATED_BODY macro and crashes.
The Init method itself is called like this:
Below is the latest log (if you can read something from it, I certainly can’t)
[CrashLog][3]
and the full source code for the inventory component
Help? Please?