UCanvas - DrawText() leads to 'Pure virtual function being called' crashes caused by Font

I’m doing a simple DrawText operation in my Custom GameViewportClient:
At Init() in my GameViewportClient I load my font successfully (checking GetName). BTW: The same crashes also happens with a copy of Engine Font ‘Roboto’.

TestFont = LoadObject<UFont>(nullptr, TEXT("Font'/Game/Henry/Fonts/My_Font.My_Font'"));

my drawtext call

Canvas->DrawText(TestFont, TestText, 0.0f, 0.0, 1.0f, 1.0f, FontRenderInfo);

BTW: using the GEngine quick version works fine:

Canvas->DrawText(GEngine->GetLargeFont(), TestText, 0.0f, 0.0f, 1.0f, 1.0f, FontRenderInfo);

Using font loaded with LoadObject consistently causes a crash ‘Pure virtual function being called’

...
UE4Editor-Core.dll!FOutputDevice::LogfImpl() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Core\Private\Misc\OutputDevice.cpp:61]
UE4Editor-Core.dll!PureCallHandler() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Core\Private\Windows\WindowsPlatformMisc.cpp:477]
VCRUNTIME140.dll!UnknownFunction []
UE4Editor-SlateCore.dll!FSlateFontInfo::FSlateFontInfo() [D:\Build\++UE4\Sync\Engine\Source\Runtime\SlateCore\Private\Fonts\SlateFontInfo.cpp:83]
UE4Editor-Engine.dll!UFont::GetCharSize() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Engine\Private\Font.cpp:202]
...

Checking Engine\Source\Runtime\SlateCore\Private\Fonts\SlateFontInfo.cpp:

82: const IFontProviderInterface* FontProvider = Cast<const IFontProviderInterface>(InFontObject);
83: if (!FontProvider || !FontProvider->GetCompositeFont())

FontProvider->GetCompositeFont() acutally is a pure virtual function, and this one seems to get called internally. From FontProviderInterface.h:

class IFontProviderInterface
{
	GENERATED_IINTERFACE_BODY()

	virtual const FCompositeFont* GetCompositeFont() const = 0;
};

It also seems to be influenced by the Font Cache Type: my font and roboto are Font Cache Type “Runtime”. Testing with a copy of engine font RobotoDistancefield, which is Cache type “Offline” behaves different, but also creates a crash in DrawStringInternal_OfflineCache()…

Anyone having an idea, what I could be doing wrong?
Thank you

Hi, I just want to share the results from this problem. The root cause was, that I did the LoadObject() during Init() of my custom UGameViewportClient.

Now, a new level gets loaded and I did trigger Draw Commands in my overridden PostRender() function including the the DrawText referencing the Font.

The new level load seems to invalidate the Font resource. Doing the LoadObject at another place (a module that I’m writing), I just need to refresh the pointer in my GameViewportClient when the module handles FCoreUObjectDelegates::PostLoadMapWithWorld().

Now it works like a charm.

P.S.: I am still not sure, if that FontProvider stuff, that gets triggered by the missing font is erroneously calling a pure virtual function anyway.