Crash on AHUD::DrawTextureSimple

Inside the editor this all runs fine and has zero issue. The crash ONLY occurs in a build or when running as a standalone game. Tested on both linux and windows and it occurs on both. When it crashes it renders the crosshair fine for about 5 minutes then crashes.

[2022.10.21-00.26.20:474][709]LogCore: Error: appError called: Assertion failed: InTexture [File:./Runtime/Engine/Private/UserInterface/CanvasItem.cpp] [Line: 316]

backtrace points to

.../Source/xxxx/Private/ShedHUD.cpp:69

which i simplified to the following and it still occurs

void AShedHUD::BeginPlay()
{
    Super::BeginPlay();
    cross = LoadObject<UTexture>(GetWorld(), TEXT("/Game/UserInterface/crosshairs/crosshair_default"));
}


void AShedHUD::DrawHUD()
{
    Super::DrawHUD();
    float x = Canvas->ClipX * 0.5;
    float y = Canvas->ClipY * 0.5;
    if(cross) {
        DrawTextureSimple(cross, x-64, y-64); //line 69
    }
}

Very odd to me that it works fine inside the editor but not outside of the editor

Any ideas?

The issue seems to have gone away by moving

cross = LoadObject<UTexture>(GetWorld(), TEXT("/Game/UserInterface/crosshairs/crosshair_default"));

into the constructor instead of BeginPlay(), not sure why this would matter as it would work for a few minutes before crashing

Avoid referencing assets from c++ code.

Declare a BP default in your header :

UPROPERTY(EditAnywhere)
UTexture* Cross;

Then make a BP subclass of your native class (eg: BP_ShedHUD), and point Cross to your asset in the BP subclass.

Then make sure your game is using the BP subclass and not the native class for HUD. This should be part of the overridable classes in GameMode

image

1 Like

Thanks,

This did solve the issue as well. Was just hoping to do it all in C++,
But i do see it being beneficial to be able to change this in BP’s