It was to my understanding that UPROPERTY() properties are automatically zeroed by the Unreal Engine. Apparently I was wrong when I ran into this problem. As you can see: 0xcdcdcdcdcdcdcdcd is the garbage assigned to the PSC pointer, hence causing an access violation. So should I start initializing all my UPROPERTY() properties in USTRUCT() structures? Or is this a bug? Thank you for your time.
Fatal error: [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.8\Engine\Source\Runtime\CoreUObject\Private\UObject\GarbageCollection.cpp] [Line: 366]
Invalid object in GC: 0xcdcdcdcdcdcdcdcd, ReferencingObject: CrashSystem /Engine/Transient.World_2:PersistentLevel.CrashSystem_0, ReferencingObjectClass: Class /Script/Celestial.CrashSystem, Property Name: PSC, Offset: 8, TokenIndex: 23
KERNELBASE.dll {0x000007fefd80b3dd} + 0 bytes
UE4Editor-Core.dll!FOutputDeviceWindowsError::Serialize() {0x000007fedb567c0f} + 0 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\sou
UE4Editor-Core.dll!FOutputDevice::Logf__VA() {0x000007fedb4210b8} + 159 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\sou
UE4Editor-Core.dll!FDebug::AssertFailed() {0x000007fedb3f1e72} + 65 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\sou
UE4Editor-CoreUObject.dll!FArchiveRealtimeGC::ProcessObjectArray() {0x000007feddf64c97} + 654 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\sou
UE4Editor-CoreUObject.dll!TGraphTask<FArchiveRealtimeGC::FGCTask>::ExecuteTask() {0x000007feddf3a6b4} + 0 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\sou
UE4Editor-Core.dll!FTaskThread::ProcessTasks() {0x000007fedb2a651e} + 0 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\sou
UE4Editor-Core.dll!FTaskThread::ProcessTasksUntilQuit() {0x000007fedb2a674d} + 0 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\sou
UE4Editor-Core.dll!FTaskThread::Run() {0x000007fedb2b574b} + 0 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\sou
UE4Editor-Core.dll!FRunnableThreadWin::Run() {0x000007fedb5669e8} + 0 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\sou
UE4Editor-Core.dll!FRunnableThreadWin::GuardedRun() {0x000007fedb55188d} + 8 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\sou
kernel32.dll {0x00000000778659cd} + 0 bytes
ntdll.dll {0x000000007799b981} + 0 bytes
ntdll.dll {0x000000007799b981} + 0 bytes
Crash in runnable thread TaskGraphThread 1
And the code to reproduce this error. The way I get this error is by creating a Blueprint Class and parenting it to the CrashGameMode. Then hit “Compile” and it should crash.
USTRUCT(BlueprintType)
struct FDumpData
{
GENERATED_USTRUCT_BODY()
public:
/** */
UPROPERTY(BlueprintReadWrite)
UParticleSystemComponent* PSC;
//
// Fixes the crash by initializing PSC to NULL
//
//FDumpData() : PSC(NULL) {}
};
USTRUCT(BlueprintType)
struct FDumpChannel
{
GENERATED_USTRUCT_BODY()
public:
/** True if this channel has been through one-time initialization */
UPROPERTY(BlueprintReadOnly)
bool Initialized;
UPROPERTY(BlueprintReadOnly)
FDumpData Data;
};
class ACrashSystem;
USTRUCT()
struct FCrashChannel
{
GENERATED_USTRUCT_BODY()
public:
friend class ACrashSystem;
private:
/** Object channels registered to physically interact with surfaces */
UPROPERTY()
TArray<FDumpChannel> DumpChannels;
};
UCLASS(Blueprintable)
class ACrashSystem : public AInfo
{
GENERATED_BODY()
private:
UPROPERTY()
TArray<FCrashChannel> Channels;
public:
void OnConstruction(const FTransform& Transform)
{
UE_LOG(LogTemp, Warning, TEXT("CrashSystem::OnConstruction"));
// Initialize this system with the default channel
this->Channels.AddDefaulted();
FCrashChannel& Channel = this->Channels[0];
TArray<FDumpChannel>& DumpChannels = Channel.DumpChannels;
//
// This piece of code crashes the editor
DumpChannels.AddDefaulted();
//
//
FDumpChannel& DumpChan = DumpChannels[0];
DumpChan.Initialized = true;
}
};
UCLASS()
class ACrashGameState : public AGameState
{
GENERATED_BODY()
public:
ACrashSystem* CrashSys;
void OnConstruction(const FTransform& Transform) override
{
if (UWorld* World = this->GetWorld())
{
FActorSpawnParameters P;
P.Owner = this;
this->CrashSys = World->SpawnActor<ACrashSystem>(P);
}
}
};
UCLASS()
class ACrashGameMode : public AGameMode
{
GENERATED_BODY()
public:
ACrashGameMode(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
this->GameStateClass = ACrashGameState::StaticClass();
}
};