Headers crashing (On VS Build) Unreal Compiler

Whether or not this is a full on bug, or something I don’t understand about C++. But from what I gather, it seems to lean on the side of bug/fluke.

Everytime I try to compile with my custom Pawn/Character class included into my header file. I get a “Unreal Header Generation Tool has stopped working” crash (Windows 7 -64bit) while trying to use the Build option off of Visual Studio 2013.

My assumption is that there is some sort of overlapping inclusion from both ROTWeapon and ROTPlayerSoldier referrencing each other, and it probably doesn’t like it or ends up in an endless loop (just guessing). I tried using #ifndef even though #pragma once is engaged, which SHOULD stop this from including the files multiple times. But to no luck.

#ifndef “ROTWeapon.h”
#define “ROTWeapon.h”
#endif

Here are my files + the crash screenshot.

ROTWeapon.h
#pragma once

#include "ROTInvManager.h"
#include "ROTPlayerSoldier.h" //Currently causing a crash
#include "ROTBullet.h"
#include "ROTInventoryItem.h"
#include "ROTWeapon.generated.h"

/**
 * 
 */
UCLASS(Blueprintable)
class AROTWeapon : public AROTInventoryItem
{
	GENERATED_UCLASS_BODY()

	
	UPROPERTY(EditAnywhere,BlueprintReadWrite,Category = "Weapon")
	TSubclassOf<class AROTBullet> Caliber;


	void BeginFire();
	void EndFire();
		
protected:
	AROTPlayerSoldier* Instigator;
};

ROTWeapon.cpp

#include "ROT.h"
#include "ROTWeapon.h"


AROTWeapon::AROTWeapon(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{

}


void AROTWeapon::BeginFire()
{
	if(GEngine)
		GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::White, TEXT("BANG"));
}

void AROTWeapon::EndFire()
{
}

ROTPlayerSoldier.h

#pragma once

#include "ROTWeapon.h"
#include "ROTInventoryItem.h"
#include "GameFramework/Character.h"
#include "ROTPlayerSoldier.generated.h"



/**
 * 
 */
UCLASS()
class AROTPlayerSoldier : public ACharacter
{
	GENERATED_UCLASS_BODY()
	
	
	//Character components
	UPROPERTY()
	TSubobjectPtr<class UCameraComponent> CameraComponent;

	//Meshes (Default "Mesh" - Main body mesh that acts as a Parent for all other meshes)
	UPROPERTY()
	TSubobjectPtr<class USkeletalMeshComponent> HeadMesh; //Head/Face


	UPROPERTY()
	AROTInventoryItem* EquippedItem; //The active item

	UFUNCTION(Exec)
		void GiveItem();
	
	//Movement
	UFUNCTION()
		virtual void MoveForward(float Value);
	UFUNCTION()
		virtual void MoveRight(float Value);
	UFUNCTION(Exec)
		void AdjustWalkSpeed(float Value);

	virtual void BeginPlay();

	//Called on server only when the Pawn becomes Possessed
	virtual void PossedBy(class AController* NewController);
	
	UFUNCTION()
		void BeginFire();
	UFUNCTION()
		void EndFire();
		
		
};

ROTPlayerSoldier.cpp

#include "ROT.h"
#include "ROTPlayerSoldier.h"


AROTPlayerSoldier::AROTPlayerSoldier(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{	
	
	//Movement
	CharacterMovement->MaxWalkSpeed = 150;
	
	
	//=== Components ===
	RootComponent = CapsuleComponent;

	//Collision Info
	
	CapsuleComponent->InitCapsuleSize(16, 48);
	
	
	//Camera info
	CameraComponent = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("CameraComponent"));
	CameraComponent->AttachParent = RootComponent;
	CameraComponent->SetRelativeLocation(FVector(0, 0, 40));
	
	//=== Inventory && Character Loading ====
	//Mesh information
	static ConstructorHelpers::FObjectFinder<USkeletalMesh> TempMesh (TEXT("/Game/Characters/SK_CH_Characters_JackSkellieton.SK_CH_Characters_JackSkellieton"));
	Mesh->SkeletalMesh =  (USkeletalMesh*)TempMesh.Object;
	Mesh->RelativeLocation = FVector(0, 0, -44);
	Mesh->RelativeRotation = FRotator(0, -90, 0);
	

	HeadMesh = PCIP.CreateOptionalDefaultSubobject<USkeletalMeshComponent>(this, TEXT("HeadMesh"));
	HeadMesh->AttachParent = Mesh;
	static ConstructorHelpers::FObjectFinder<USkeletalMesh> TempMesh1(TEXT("/Game/Characters/SK_CH_Characters_HeadTest.SK_CH_Characters_HeadTest"));
	HeadMesh->SkeletalMesh = (USkeletalMesh*)TempMesh1.Object;

	//Inventory
}

void AROTPlayerSoldier::BeginFire()
{
	if (!EquippedItem)
		return;

	Cast<AROTWeapon>(EquippedItem)->BeginFire();
}

void AROTPlayerSoldier::EndFire()
{}

void AROTPlayerSoldier::BeginPlay()
{
	
}

void AROTPlayerSoldier::PossedBy(class AController* NewController)
{

}

void AROTPlayerSoldier::MoveForward(float Value)
{
}

void AROTPlayerSoldier::MoveRight(float Value)
{
}

void AROTPlayerSoldier::AdjustWalkSpeed(float Value)
{
	CharacterMovement->MaxWalkSpeed = Value;
}

void AROTPlayerSoldier::GiveItem()
{
	//static ConstructorHelpers::FObjectFinder<UClass> WeapTest(TEXT("Class'/Game/Weapons/M4A1/BP_WP_M4A1.BP_WP_M4A1'"));
	//static ConstructorHelpers::FObjectFinder<UBlueprint> WeapBP(TEXT("Blueprint'/Game/Weapons/M4A1/BP_WP_M4A1.BP_WP_M4A1'"));
	

	EquippedItem = GetWorld()->SpawnActor<AROTWeapon>(AROTWeapon::StaticClass());

	//WeapTest2 = (UClass*)WeapTest.Object->GeneratedClass;
	//EquippedItem = GetWorld()->SpawnActor<AROTWeapon.
}

There was a bug in UHT where it would crash if it found a cyclic dependency between headers.

This particular crash is fixed by https://github.com/EpicGames/UnrealEngine/commit/91c7acd3a8d6b5f30816472e60a66ede51e3ee55

Unfortunately the layout of UHT has changed between 4.1 and that fix, so it won’t merge in cleanly. I provided some more information on the following question with regards to manually merging the fix into 4.1.

Although I do have the engine code downloaded to look through, I’d really rather not start modifying it.

I guess the best thing to do is just throw some of my multiple includes inside my main project header until 4.2 is released (to which I’m hoping it will then be fixed?)

Yeah, 4.2 should hopefully fix the issue (I’ve made a request for that fix to be merged into 4.2 anyway).

I decided to attempt your fix, due to the annoyance the problem was causing me, and the crash still happens.

I had the 4.1 source code downloaded. Opened the HeaderParser.cpp file and added the code as such. Compiled using Developer Editor - Win64 (just like the UE4 source is said to be compiled at) which created a new UnrealHeaderTool.exe, I took that .exe and dropped it into my 4.1 installation (C:\ProgramFiles\UnrealEngine\4.1\Binaries\Win64) while backing up the original UnrealHeaderTool.exe.

I restarted visual studio for my project, and tried a “Build” (F7) and the same thing happened. Did I misunderstand the fix, or is there something else happening?

Hi, sorry for the delay.

I’ve tried your code here and I get the expected ‘Class ROTWeapon DependsOn(ROTPlayerSoldier) is a circular dependency’ error.

Your changes should look something like this:

Can you confirm that this is what you have? Also, can you confirm that you’ve definitely replaced UE4\Engine\Binaries\Win64\UnrealHeaderTool.exe?

But it should be simple to avoid this recursive dependency in the first place. Let me know and we can help.

Steve