ConstructorHelpers::FClassFinder causing project to crash

inside the constructor of my class derived from AHUD i have

ConstructorHelpers::FClassFinder<UMyWidgetClass> classreference(TEXT("WidgetBlueprint'/Game/MyAssets/Blueprints/GameHUD.GameHUD_C'"));
	if (classreference.Succeeded())
	{
		classreference.Class->AddToRoot();
		GameHUDclass = classreference.Class;
     }

which loads a widget blueprint class so i can display to the screen, it works, but if i close the project and try to reopen, it crashes at lauch. The only way the solve this crash is to open visual studio and comment these lines of code and build.

if i uncomment and build, it works normally, but guess what happens if i close the editor and try to reopen? it crashes. The editor loads up to 70% and then crashes in these cases.

am i doing something wrong with the use of contructorhelpers?

EDIT:
CrossHair.cpp

#include "MyProject.h"
#include "CrossHair.h"




ACrossHair::ACrossHair()
{
	/*ConstructorHelpers::FClassFinder<UMyWidgetClass> classreference(TEXT("WidgetBlueprint'/Game/MyAssets/Blueprints/GameHUD.GameHUD_C'"));
	if (classreference.Succeeded())
	{
		classreference.Class->AddToRoot();
		GameHUDclass = classreference.Class;
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Achou?"));
	}
	else
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("nao achou"));
	}*/

	ConstructorHelpers::FObjectFinderOptional<UTexture> TextureFinder(TEXT("/Game/MyAssets/Textures/spr_bulletE_0.spr_bulletE_0"));
	if (TextureFinder.Succeeded())
	{
		m_crossHairTexture = TextureFinder.Get();
		m_drawCrossHair = true;
	}
//create crosshair sprite

	if (GetWorld())
	{
		FVector2D screen = GEngine->GameViewport->Viewport->GetSizeXY();
		m_screenCenter = FVector2D(screen.X / 2, screen.Y / 2);
		if (GameHUDclass)
		{
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("nao eh null"));
			if (!m_gameHud)
			{
				m_gameHud = CreateWidget<UMyWidgetClass>(GetWorld(), GameHUDclass);
				if (m_gameHud)
				{
					GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("criou"));
					m_gameHud->AddToViewport();
				}
			}
		}
	}
	else
	{
		m_screenCenter = FVector2D(500, 500);
	}
	
}
void ACrossHair::DrawCrossHair()
{ 
	DrawTextureSimple(m_crossHairTexture, m_screenCenter.X, m_screenCenter.Y, 1.0f, true);
}
void ACrossHair::PostInitializeComponents()
{
	
	
	Super::PostInitializeComponents();

	
}
void ACrossHair::DrawHUD()
{
	if (m_drawCrossHair)
	{
		DrawCrossHair();
	}
}

CrossHair.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "MyWidgetClass.h"
#include "GameFramework/HUD.h"
#include "BaseCharacter.h"
#include "CrossHair.generated.h"


/**
 * 
 */
UCLASS(Blueprintable)
class MYPROJECT_API ACrossHair : public AHUD
{
	GENERATED_BODY()

public:
	//cross hair
	UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "CrossHair")
		UTexture* m_crossHairTexture;
	UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "CrossHair")
		bool m_drawCrossHair;
	UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "CrossHair")
		FVector2D m_screenCenter;
	UFUNCTION()
		void DrawCrossHair();

	//health bar
protected:
	UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "CrossHair")
		TSubclassOf<UMyWidgetClass> GameHUDclass;
	UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "CrossHair")
		UMyWidgetClass* m_gameHud;

	UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "CrossHair")
		ABaseCharacter* PlayerCharacterReference;
	
	//constructor
	ACrossHair();

	//class overrides
	virtual void DrawHUD() override;
	virtual void PostInitializeComponents() override;	
};

the most recent log

Log file open, 03/31/16 17:22:55
LogInit:Display: Running engine for game: MyProject
LogPlatformFile: Not using cached read wrapper
LogInit:Display: RandInit(-1001754272) SRandInit(-1001754271).
LogTaskGraph: Started task graph with 4 named threads and 7 total threads.
LogStats: Stats thread started at 0.068253
LogHMD: Can't find Oculus library dev build: is proper Runtime installed? Version: 0.8.0.0
LogInit: Version: 4.11.0-2916259+++UE4+Release-4.11
LogInit: API Version: 2916259
LogInit: Compiled (64-bit): Mar 21 2016 02:14:00
LogInit: Compiled with Visual C++: 19.00.23026.00
LogInit: Build Configuration: Development
LogInit: Branch Name: ++UE4+Release-4.11
LogInit: Command line:  
LogInit: Base directory: C:/Program Files/Epic Games/4.11/Engine/Binaries/Win64/
LogInit: Installed Engine Build: 1
LogInit: Using libcurl 7.41.0
LogInit:  - built for x86_64-pc-win32
LogInit:  - supports SSL with WinSSL
LogInit:  - other features:
LogInit:      CURL_VERSION_SSL
LogInit:      CURL_VERSION_IPV6
LogInit:      CURL_VERSION_ASYNCHDNS
LogInit:      CURL_VERSION_LARGEFILE
LogInit:      CURL_VERSION_IDN
LogInit:  CurlRequestOptions (configurable via config and command line):
LogInit:  - bVerifyPeer = true  - Libcurl will verify peer certificate
LogInit:  - bUseHttpProxy = false  - Libcurl will NOT use HTTP proxy
LogInit:  - bDontReuseConnections = false  - Libcurl will reuse connections
LogInit:  - CertBundlePath = nullptr  - Libcurl will use whatever was configured at build time.
LogInit: Presizing for max 16777216 objects, including 0 objects not considered by GC, pre-allocating 0 bytes for permanent pool.
LogInit: Object subsystem initialized
[2016.03.31-20.22.55:366][  0]LogInit: Selected Device Profile: [Windows]
[2016.03.31-20.22.55:366][  0]LogInit: Applying CVar settings loaded from the selected device profile: [Windows]
[2016.03.31-20.22.55:380][  0]LogInit: Computer: GABRIEL-PC
[2016.03.31-20.22.55:380][  0]LogInit: User: gabri000
[2016.03.31-20.22.55:380][  0]LogInit: CPU Page size=65536, Cores=4
[2016.03.31-20.22.55:380][  0]LogInit: High frequency timer resolution =3.507515 MHz
[2016.03.31-20.22.55:380][  0]LogMemory: Memory total: Physical=8.0GB (8GB approx)
[2016.03.31-20.22.55:380][  0]LogMemory: Platform Memory Stats for Windows
[2016.03.31-20.22.55:380][  0]LogMemory: Process Physical Memory: 313.96 MB used, 313.96 MB peak
[2016.03.31-20.22.55:380][  0]LogMemory: Process Virtual Memory: 314.94 MB used, 314.94 MB peak
[2016.03.31-20.22.55:380][  0]LogMemory: Physical Memory: 3915.41 MB used, 8143.20 MB total
[2016.03.31-20.22.55:380][  0]LogMemory: Virtual Memory: 652.91 MB used, 134217728.00 MB total
[2016.03.31-20.22.55:443][  0]LogTextLocalizationManager: No specific translations for ('en-US') exist, so ('en') translations will be used.
[2016.03.31-20.22.55:798][  0]LogD3D11RHI: D3D11 adapters:
[2016.03.31-20.22.55:818][  0]LogD3D11RHI:    0. 'NVIDIA GeForce GT 720' (Feature Level 11_0)
[2016.03.31-20.22.55:818][  0]LogD3D11RHI:       973MB of dedicated video memory, 0MB of dedicated system memory, and 4071MB of shared system memory, 2 output[s]
[2016.03.31-20.22.55:819][  0]LogD3D11RHI:    1. 'Microsoft Basic Render Driver' (Feature Level 11_0)
[2016.03.31-20.22.55:819][  0]LogD3D11RHI:       0MB of dedicated video memory, 0MB of dedicated system memory, and 4071MB of shared system memory, 0 output[s]
[2016.03.31-20.22.55:819][  0]LogD3D11RHI: Chosen D3D11 Adapter: 0
[2016.03.31-20.22.55:822][  0]LogD3D11RHI: Creating new Direct3DDevice
[2016.03.31-20.22.55:822][  0]LogD3D11RHI:     Adapter Name: NVIDIA GeForce GT 720
[2016.03.31-20.22.55:822][  0]LogD3D11RHI:   Driver Version: 10.18.13.6175 (internal 10.18.13.6175)
[2016.03.31-20.22.55:822][  0]LogD3D11RHI:      Driver Date: 1-22-2016
[2016.03.31-20.22.55:822][  0]LogRHI: Texture pool is 681 MB (70% of 973 MB)
[2016.03.31-20.22.55:833][  0]LogD3D11RHI: Async texture creation enabled
[2016.03.31-20.22.55:848][  0]LogShaderCompilers: Guid format shader working directory is -29 characters bigger than the processId version (../../../../../../Users/gabri_000/Documents/Unreal Projects/MyProject 4.11 - 2/Intermediate/Shaders/WorkingDirectory/4068/).
[2016.03.31-20.22.55:849][  0]LogShaderCompilers: Cleaned the shader compiler working directory 'C:/Users/GABRI_~1/AppData/Local/Temp/UnrealShaderWorkingDir/9C3F604947C7D3BFFD47F0B7735CC61D/'.
[2016.03.31-20.22.55:849][  0]LogShaderCompilers:Display: Using Local Shader Compiler.
[2016.03.31-20.22.57:058][  0]LogTemp:Display: Loaded TP AllDesktopTargetPlatform
[2016.03.31-20.22.57:062][  0]LogTemp:Display: Loaded TP WindowsClientTargetPlatform
[2016.03.31-20.22.57:065][  0]LogTemp:Display: Loaded TP WindowsNoEditorTargetPlatform
[2016.03.31-20.22.57:068][  0]LogTemp:Display: Loaded TP WindowsServerTargetPlatform
[2016.03.31-20.22.57:072][  0]LogTemp:Display: Loaded TP WindowsTargetPlatform
[2016.03.31-20.22.57:077][  0]LogTemp:Display: Loaded TP AndroidTargetPlatform
[2016.03.31-20.22.57:080][  0]LogTemp:Display: Loaded TP Android_ASTCTargetPlatform
[2016.03.31-20.22.57:082][  0]LogTemp:Display: Loaded TP Android_ATCTargetPlatform
[2016.03.31-20.22.57:085][  0]LogTemp:Display: Loaded TP Android_DXTTargetPlatform
[2016.03.31-20.22.57:088][  0]LogTemp:Display: Loaded TP Android_ETC1TargetPlatform
[2016.03.31-20.22.57:090][  0]LogTemp:Display: Loaded TP Android_ETC2TargetPlatform
[2016.03.31-20.22.57:095][  0]LogTemp:Display: Loaded TP Android_MultiTargetPlatform
[2016.03.31-20.22.57:095][  0]LogTemp:Display: Loaded TP Android_PVRTCTargetPlatform
[2016.03.31-20.22.57:095][  0]LogTemp:Display: Loaded TP HTML5TargetPlatform
[2016.03.31-20.22.57:112][  0]LogTemp:Display: Loaded TP IOSTargetPlatform
[2016.03.31-20.22.57:114][  0]LogTemp:Display: Loaded TP TVOSTargetPlatform
[2016.03.31-20.22.57:116][  0]LogTemp:Display: Loaded TP LinuxNoEditorTargetPlatform
[2016.03.31-20.22.57:118][  0]LogTemp:Display: Loaded TP LinuxServerTargetPlatform
[2016.03.31-20.22.57:123][  0]LogTemp:Display: Loaded TP LinuxTargetPlatform
[2016.03.31-20.22.57:123][  0]LogTargetPlatformManager:Display: Building Assets For Windows
[2016.03.31-20.22.57:181][  0]LogDerivedDataCache:Display: Max Cache Size: 512 MB
[2016.03.31-20.22.57:220][  0]LogDerivedDataCache: Loaded boot cache 0.04s 46MB C:/Users/gabri_000/AppData/Local/UnrealEngine/4.11/DerivedDataCache/Boot.ddc.
[2016.03.31-20.22.57:220][  0]LogDerivedDataCache:Display: Loaded Boot cache: C:/Users/gabri_000/AppData/Local/UnrealEngine/4.11/DerivedDataCache/Boot.ddc
[2016.03.31-20.22.57:220][  0]LogDerivedDataCache: FDerivedDataBackendGraph:  Pak pak cache file ../../../../../../Users/gabri_000/Documents/Unreal Projects/MyProject 4.11 - 2/DerivedDataCache/DDC.ddp not found, will not use a pak cache.
[2016.03.31-20.22.57:220][  0]LogDerivedDataCache: Unable to find inner node Pak for hierarchical cache Hierarchy.
[2016.03.31-20.22.57:220][  0]LogDerivedDataCache: FDerivedDataBackendGraph:  CompressedPak pak cache file ../../../../../../Users/gabri_000/Documents/Unreal Projects/MyProject 4.11 - 2/DerivedDataCache/Compressed.ddp not found, will not use a pak cache.
[2016.03.31-20.22.57:220][  0]LogDerivedDataCache: Unable to find inner node CompressedPak for hierarchical cache Hierarchy.
[2016.03.31-20.22.57:233][  0]LogDerivedDataCache:Display: Pak cache opened for reading ../../../Engine/DerivedDataCache/Compressed.ddp.
[2016.03.31-20.22.57:245][  0]LogDerivedDataCache: Using Local data cache path C:/Users/gabri_000/AppData/Local/UnrealEngine/Common/DerivedDataCache: Writable
[2016.03.31-20.22.57:369][  0]LogInit: Selected Device Profile: [Windows]
[2016.03.31-20.22.57:369][  0]LogContentStreaming: Texture pool size is 0.00 MB
[2016.03.31-20.22.57:395][  0]LogMaterial: Uniform references updated for custom material expression Custom.
[2016.03.31-20.22.57:494][  0]LogMeshUtilities: No automatic mesh reduction module available
[2016.03.31-20.22.57:494][  0]LogMeshUtilities: No automatic mesh merging module available
[2016.03.31-20.22.57:494][  0]LogMeshUtilities: No distributed automatic mesh merging module available
[2016.03.31-20.22.57:730][  0]LogUObjectArray: 27671 objects as part of root set at end of initial load.
[2016.03.31-20.22.57:730][  0]LogUObjectAllocator: 5589752 out of 0 bytes used by permanent object pool.
[2016.03.31-20.22.57:730][  0]LogUObjectArray: CloseDisregardForGC: 0/0 objects in disregard for GC pool
[2016.03.31-20.22.57:735][  0]LogInit: WinSock: version 1.1 (2.2), MaxSocks=32767, MaxUdp=65467
[2016.03.31-20.22.57:857][  0]LogSlate: SlateFontCache - WITH_FREETYPE: 1, WITH_HARFBUZZ: 1
[2016.03.31-20.22.57:857][  0]LogSlate: SlateFontCache - WITH_FREETYPE: 1, WITH_HARFBUZZ: 1
[2016.03.31-20.22.59:359][  0]LogStreaming:Warning: Failed to read file '../../../Engine/Content/Editor/Slate/Common/Selection_16x.png' error.
[2016.03.31-20.22.59:359][  0]LogSlate: Could not find file for Slate resource: ../../../Engine/Content/Editor/Slate/Common/Selection_16x.png
[2016.03.31-20.22.59:359][  0]LogStreaming:Warning: Failed to read file '../../../Engine/Content/Editor/Slate/Common/Selection_16x.png' error.
[2016.03.31-20.22.59:359][  0]LogSlate: Could not find file for Slate resource: ../../../Engine/Content/Editor/Slate/Common/Selection_16x.png
[2016.03.31-20.22.59:359][  0]LogStreaming:Warning: Failed to read file '../../../Engine/Content/Editor/Slate/Common/Selection_16x.png' error.
[2016.03.31-20.22.59:359][  0]LogSlate: Could not find file for Slate resource: ../../../Engine/Content/Editor/Slate/Common/Selection_16x.png
[2016.03.31-20.23.04:294][  0]LogUdpMessaging: Initializing bridge on interface 0.0.0.0:0 to multicast group 230.0.0.1:6666.
[2016.03.31-20.23.08:712][  0]LogWindows:Error: === Critical error: ===
Fatal error!



[2016.03.31-20.23.08:788][  0]LogExit: Executing StaticShutdownAfterError
[2016.03.31-20.23.08:790][  0]LogWindows: FPlatformMisc::RequestExit(1)
[2016.03.31-20.23.08:790][  0]Log file closed, 03/31/16 17:23:08

Hello,

Could you please provide the full code (.h + .cpp) that you are using when you are seeing this crash? I wasn’t able to reproduce it using the snippet you’ve provided, which leads me to believe I’m setting something up a bit differently on my end.

i posted the full code for the HUD class, i didn’t know where i could upload to make it easier to visualize, so i just edit the original post

Thank you. Since this is a crash, could you please provide the logs from your project’s Saved->Logs folder after the crash occurs?

Also, could you cause the crash again and provide your Machine ID from the crash reporter window and ensure that you hit send on the report?

the machine ID is: 9291D07241CC5EC74D610AACFA55E692

This is the most recent log: http://codepaste.net/cfz9nm

Have you been able to determine if it is the FClassFinder function entirely, or if it is a specific line that you have that is causing the crash?

Go ahead and comment out these lines one at a time and see if one of them could be causing the crash to occur:

classreference.Class->AddToRoot();
GameHUDclass = classreference.Class;

yeah it wasnt the classfinder, and neither the addtoroot or the class reference assignment, it was the debugmessage

GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Achou?"));

if this is commented then the editor doesnt crash at lauch and i able to display the widget to the screen

You’ll need to #include “Engine.h” as well if you want to access GEngine functions. So go ahead and add that include and see if that helps.

i tested it and it crashed.
i have other debug messages in the cpp and they work, it’s just inside that “if succeeded” that makes the editor crash

It looks like you are pointing to your HUD blueprint with your FClassFinder, so try using FObjectFinder instead and see if you still get the same crash.

Also, when you are using AddToRoot(), what are you trying to accomplish? As far as I know, AddToRoot would attach a component to the root component of a blueprint, but the HUD blueprint typically does not contain components, which would mean that you aren’t necessarily attaching it to anything. This could cause issues as well.

i used fobjectfinder and it couldn’t create the widget.

the addToRoot was a previous attempt to fix the crash based on other user questions, i removed it and nothing changed.

i think i’m gonna mark as solved, the AddOnScreenDebugMessage
was causing the crash, i think these just aren’t supposed to be in the constructor of the class

Hello,

I am marking this topic as resolved as it was stated that taking the Add OnScreen Debug Message call in the constructor was the root of the issue. If this issue returns, please feel free to return to this thread and post a comment and we can continue to investigate.

Have a great day