EXCEPTION_ACCESS_VIOLATION When using .Num() on a array, can anyone help me with this?

Hey so I’ve been having problems with accessing the data tables stored in my data asset blueprint to load them into memory, when I try and call LoadSoftRef I get the below error from what I can tell this is being caused by calling the .Num() method on DataTables_Array array (This happens no matter what method I call from array).

Any help would be appreciated with this problem?

Error message
Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x0000000000000070

UE4Editor_UnrealCOC_1620!UDataTable_DataAsset::LoadSoftRef() [E:\UE4 games\UnrealCOC\Source\UnrealCOC\DataTable_DataAsset.cpp:9]
UE4Editor_UnrealCOC_1620!UTestAppearance_Class::PlayerAppearanceCon() [E:\UE4 games\UnrealCOC\Source\UnrealCOC\TestAppearance_Class.cpp:15]
UE4Editor_UnrealCOC_1620!UTestAppearance_Class::execPlayerAppearanceCon() [E:\UE4 games\UnrealCOC\Intermediate\Build\Win64\UE4Editor\Inc\UnrealCOC\TestAppearance_Class.gen.cpp:31]
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_UMG
UE4Editor_UMG
UE4Editor_UMG
UE4Editor_UMG
UE4Editor_UMG
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor
UE4Editor
UE4Editor
UE4Editor
UE4Editor
UE4Editor
kernel32
ntdll

Code
DataTable_DataAsset.h

15 UCLASS(Blueprintable)
16 class UNREALCOC_API UDataTable_DataAsset : public UDataAsset
17 {
18	GENERATED_BODY()
19
20 public:
21	//StreamHandle
22	TSharedPtr<FStreamableHandle> Handle;
23
24	TArray<FSoftObjectPath> Paths;
25
26	FStreamableDelegate Delegate = FStreamableDelegate::CreateUObject(this, &UDataTable_DataAsset::Del);
27
28	UPROPERTY(EditAnywhere, Category = "DataTables")
29	TArray<TSoftObjectPtr<UDataTable>> DataTables_Array;
30
31	UFUNCTION(BlueprintCallable, Category = "Data Async Load Helper")
32	void LoadSoftRef(UUnrealGameInstance* UGI);
33
34	UFUNCTION(BlueprintCallable, Category = "Data Async Unload Helper")
35	void UnloadSoftRef();
36
37	UFUNCTION(BlueprintCallable, Category = "Delegate")
38	void Del();
39 };

DataTable_DataAsset.cpp

7 void UDataTable_DataAsset::LoadSoftRef(UUnrealGameInstance* UGI) {
8
9 	for (int32 Index = 0; Index < DataTables_Array.Num();Index++) {
10 		Paths.AddUnique(DataTables_Array[Index].ToSoftObjectPath());
11 	}
12
13	Handle = UGI->AssetLoader.RequestAsyncLoad(Paths, Delegate);
14 }
15
16
17 void UDataTable_DataAsset::UnloadSoftRef() {
18	Handle.Get()->ReleaseHandle();
19
20 }
21
22
23 void UDataTable_DataAsset::Del() {
24	while (!Handle.Get()->HasLoadCompleted()) {
25
26	}
27 }

UnrealGameInstance.h

UCLASS()
class UNREALCOC_API UUnrealGameInstance : public UGameInstance
{
	GENERATED_BODY()

public:
	UUnrealAssetManager& UAM = UUnrealAssetManager::GetObj();

	FTempSettings_Struct TempSettings;

	FPermSettings_Struct PermSettings;

	FDT_Ref_Struct DT_Ref2;

	FStreamableManager AssetLoader;

	UDataTable_DataAsset* TDataAsset = LoadObject<UDataTable_DataAsset>(NULL, TEXT("/Game/DataAsset/AssetDT.AssetDT"), NULL, LOAD_None, NULL);

	void SetDT_Ref();

	UUnrealGameInstance();

};

TestAppearance.cpp

7 FString UTestAppearance_Class::PlayerAppearanceCon(ACharacter* CPlayer, UGameInstance* GI) {
8	APlayerCharacter_Class* Data_Player = Cast<APlayerCharacter_Class>(CPlayer);
9	UUnrealGameInstance* Data_GI = Cast<UUnrealGameInstance>(GI);
10	FString AppearanceDescription = "";
11
12	Data_GI->TDataAsset ->LoadSoftRef(Data_GI);
13
14
15
16
17	return AppearanceDescription;
18 }

Seems like you are looping through an empty array.

Try:

for (int32 Index = 0; Index < DataTables_Array.Num(); ++Index) 
{
    if (DataTables_Array[Index))
    {
        Paths.AddUnique(DataTables_Array[Index].ToSoftObjectPath());
    }
    else
    {
        // Invalid index.
        UE_LOG(LogTemp, Warning, FString::Printf(TEXT("Invalid index for DataTables_Array: %i"), Index));
    }
}

run it in debugger and see what the values of everything are. I’m guessing “this” is null somehow there.

Hey pezzott1 I tried your suggestion but I’m still getting the same error message, It’s still blowing up when when I call .Num(). Also I don’t think the arrays empty since I filled it in blueprints

Note: I had to modify the code since there where errors in it, so that’s why it isn’t the exactly the same

for (int32 Index = 0; Index < DataTables_Array.Num(); ++Index)
    {
        if (DataTables_Array[Index]) {
            Paths.AddUnique(DataTables_Array[Index].ToSoftObjectPath());

        }
        else
        {
            if (GEngine) {
                GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Invalid index for DataTables_Array: %i"));
            }
        }
    }

error
Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x0000000000000070

UE4Editor_UnrealCOC_6723!UDataTable_DataAsset::LoadSoftRef() [E:\UE4 games\UnrealCOC\Source\UnrealCOC\DataTable_DataAsset.cpp:8]
UE4Editor_UnrealCOC_6723!UTestAppearance_Class::PlayerAppearanceCon() [E:\UE4 games\UnrealCOC\Source\UnrealCOC\TestAppearance_Class.cpp:15]
UE4Editor_UnrealCOC_6723!UTestAppearance_Class::execPlayerAppearanceCon() [E:\UE4 games\UnrealCOC\Intermediate\Build\Win64\UE4Editor\Inc\UnrealCOC\TestAppearance_Class.gen.cpp:31]
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_UMG
UE4Editor_UMG
UE4Editor_UMG
UE4Editor_UMG
UE4Editor_UMG
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor
UE4Editor
UE4Editor
UE4Editor
UE4Editor
UE4Editor
kernel32
ntdll

Hi eblade I tried commenting out the delegate and async request I’m not sure if that’s enough (please let me know if that’s not enough ) but it’s blowing up at the .Num method, but I have gotten a slightly different EXCEPTION_ACCESS_VIOLATION

code

DataTable_DataAsset.h

UCLASS(Blueprintable)
class UNREALCOC_API UDataTable_DataAsset : public UDataAsset
{
	GENERATED_BODY()

public:
	//StreamHandle
	TSharedPtr<FStreamableHandle> Handle;

	TArray<FSoftObjectPath> Paths;

	//FStreamableDelegate Delegate = FStreamableDelegate::CreateUObject(this, &UDataTable_DataAsset::Del);

	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "DataTables")
	TArray<TSoftObjectPtr<UDataTable>> DataTables_Array;

	UFUNCTION(BlueprintCallable, Category = "Data Async Load Helper")
	void LoadSoftRef(UUnrealGameInstance* UGI);

	UFUNCTION(BlueprintCallable, Category = "Data Async Unload Helper")
	void UnloadSoftRef();

	UFUNCTION(BlueprintCallable, Category = "Delegate")
	void Del();
};

DataTable_DataAsset.cpp

void UDataTable_DataAsset::LoadSoftRef(UUnrealGameInstance* UGI) {

	for (int32 Index = 0; Index < DataTables_Array.Num();Index++) {
		Paths.AddUnique(DataTables_Array[Index].ToSoftObjectPath());
	}

	//Handle = UGI->AssetLoader.RequestAsyncLoad(Paths, Delegate);
}


void UDataTable_DataAsset::UnloadSoftRef() {
	Handle.Get()->ReleaseHandle();

}


void UDataTable_DataAsset::Del() {
	while (!Handle.Get()->HasLoadCompleted()) {

	}
}

error
Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x0000000000000060

UE4Editor_UnrealCOC_0590!UDataTable_DataAsset::LoadSoftRef() [E:\UE4 games\UnrealCOC\Source\UnrealCOC\DataTable_DataAsset.cpp:9]
UE4Editor_UnrealCOC_0590!UTestAppearance_Class::PlayerAppearanceCon() [E:\UE4 games\UnrealCOC\Source\UnrealCOC\TestAppearance_Class.cpp:15]
UE4Editor_UnrealCOC_0590!UTestAppearance_Class::execPlayerAppearanceCon() [E:\UE4 games\UnrealCOC\Intermediate\Build\Win64\UE4Editor\Inc\UnrealCOC\TestAppearance_Class.gen.cpp:31]
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_UMG
UE4Editor_UMG
UE4Editor_UMG
UE4Editor_UMG
UE4Editor_UMG
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor
UE4Editor
UE4Editor
UE4Editor
UE4Editor
UE4Editor
kernel32
ntdll

Somewhere, you have a “this” that is a nullptr.

Three obvious candidates:

(1) When you are calling TestAppearance:PlayerAppearanceCon, you are feeding a nullptr into the second argument, such that the value of Data_GI is nullptr in line 12 of that function.

(2) When you are calling TestAppearance:PlayerAppearanceCon, the value of TDataAsset in Data_GI is a nullptr, suggesting that perhaps it didn’t load properly.

(3) When you are calling TestAppearance:PlayerAppearanceCon, the function that calls it is calling it on a pointer that is null.

The easiest way to sort through this is to go to the function that CALLS PlayerAppearanceCon on an instance of UTestAppearance_Class, and put a breakpoint right where you call that function. Step into each line and see where you have a nullptr. There’s one somewhere in there.

Hey KelbyVP, I followed your advice and through setting up the breakpoints in C++ didn’t really work I was able to narrow the problem by doing the below, it turns out that TDataAsset was null so for some reason load object isn’t working properly, would anyone be familiar with why?. I switch over to load object and non primary data asset since I was have problems with getting to load with asset manager does any one have any one help

FString UTestAppearance_Class::PlayerAppearanceCon(ACharacter* CPlayer, UGameInstance* GI) {
	APlayerCharacter_Class* Data_Player = Cast<APlayerCharacter_Class>(CPlayer);
	UUnrealGameInstance* Data_GI = Cast<UUnrealGameInstance>(GI);
	FString AppearanceDescription = "";
        if(Data_GI->TDataAsset != nullptr){
            Data_GI->TDataAsset ->LoadSoftRef(Data_GI);
        }
	




	return AppearanceDescription;
 }

Not sure what the issue is, but try this to see if the problem is the way you are loading the data table:

I assume you have a custom Blueprint class that inherits from UUnrealGameInstance and that you are using in your game. If so:

  1. In your UnrealGameInstance class, add the following macro above the UDataTable_DataAsset declaration:
    UPROPERTY(EditDefaultsOnly)

  2. Also in your UnrealGameInstance class, comment out the = LoadObject<UDataTable_DataAsset>(NULL, TEXT("/Game/DataAsset/AssetDT.AssetDT"), NULL, LOAD_None, NULL)

  3. In the custom blueprint class, set the value of value of the the TDataAsset variable to the data table you are referencing (i.e., AssetDT)

Now see if it works.

When you run it via debugger, it’s not just the specific line of code or function call that breaks that is of interest, but also the values of the variables. It’s shouldn’t be possible to a TArray to point to bad memory, so it has to be the container of it that is bad.

I’m going to guess most likely that your properties in UnrealGameInstance.h need to be UPROPERTY otherwise they are getting garbage collected.

1 Like

Hey KelbyVP my Game instance is not a blueprint it’s a C++ class also AssetDT is a data asset sub class, AssetDT contains a array of data tables and functions to load and unload said data tables but for some reason, AssetDT won’t load no matter what method I try to use

The line breaks won’t work in C++ code it only works when I set a line break on the function PlayerAppearanceCon in blueprints, from what I can tell it’s the data asset (AssetDT) that won’t load that’s causing this error and I don’t know why it doesn’t matter if I use load object or PreloadPrimaryAssets i’ve hit a brick wall and I don’t know how to resolve it

^^^^

1 Like

I have tried adding UPROPERTY to the variable but it doesn’t fix the problem