Annoying crash using SetTimer: Newbie here

Hello everyone,

I am having this crash that I have been trying to resolve for about a month now, but I just cannot figure out what is going on. Basically I am using a Rest UObject which has a private FString variable that it initializes to some value after making a connection.

Then I have a Actor which uses a UTextRenderComponent * for the text actor. In this file, I use the GetWorld()->GetTimerManager().SetTimer(timerHandle, this, &AHospText::UpdateDisplay, 10.0f, true) method to get the FString from the Rest UObject. The UpdateDisplay method calls BuildHospString() and this is where I am having a problem. Since I want to display the private FString member that the Rest object has, BuildHospString() calls rest->GetResult() and GetResult() returns that private FString. Then BuildHospString() returns this FString and in my UpdateDisplay() I call HospText->SetText(BuildHospString());

This works fine for about a 45 seconds but then I get a crash. I just cannot figure out where I am leaking resources because the crash has to do with memory allocation for the FStrings. Here is what I get. I even tried to pass the private FString as a reference
all the way to UpdateDisplay but still no luck. I would greatly appreciate your help as eliminating this problem will help me to finally finish this project.

Here is the cpp file pseudo setup:

AHospText::AHospText()
{
//false to improve performance
PrimaryActorTick.bCanEverTick = false;

HospText = CreateDefaultSubobject<UTextRenderComponent>(TEXT("Default"));
HospText->SetHorizontalAlignment(EHTA_Center);

    //size of lettering
HospText->SetWorldSize(20.0f);
RootComponent = HospText;

}

void AHospText::BeginPlay()
{
Super::BeginPlay();

    HospText->SetText(LOCTEXT("Welcome","HOSPITAL STRING!!"));

rest = NewObject<URestClient>();

GetData();

}

void AHospText::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );

}

I have commented out control stuff because in essence I need the SetTimer to work indefinitely updating the text

//updates display text
void AHospText::UpdateDisplay()
{

//if the timer was used, clear it
//if (timerUsed)
//{
	//GetWorld()->GetTimerManager().ClearTimer(timerHandle);
	//build the hosp str

	HospText->SetText(BuildHospString());
	
           //HospStr = FText::FromString(BuildHospString());
//}

//set the hosp text
//HospText->SetText(FText::FromString(BuildHospString()));

}

//builds the display string
FString AHospText::BuildHospString()
{
//GEngine->AddOnScreenDebugMessage(-1, 30.f, FColor::Red, result);

return rest->GetResult();

}

//uses RestClient.h to get Data from a Rest Endpoint

void AHospText::GetData()
{
processed is set to true when Rest client is established

if (processed == true)
{
	//GEngine->AddOnScreenDebugMessage(-1, 30.f, FColor::Red, "AUTH IS TRUE");
	//GEngine->AddOnScreenDebugMessage(-1, 30.f, FColor::Red, rest->GetResult());
	//timer will be used
	timerUsed = true;
	//20 second timer
	GetWorld()->GetTimerManager().SetTimer(timerHandle, this, &AHospText::UpdateDisplay, 10.0f, true);
}

}

#undef LOCTEXT_NAMESPACE

Here is the Crash Report:

MachineId:
EpicAccountId:

Fatal error: [File:D:\BuildFarm\buildmachine_++UE4+Release-4.11\Engine\Source\Runtime\Core\Private\GenericPlatform\GenericPlatformMemory.cpp] [Line: 139]
Ran out of memory allocating 18446744072564227002 bytes with alignment 0

UE4Editor_Core!FDebug::AssertFailed() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\core\private\misc\outputdevice.cpp:430]
UE4Editor_Core!FGenericPlatformMemory::OnOutOfMemory() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\core\private\genericplatform\genericplatformmemory.cpp:140]
UE4Editor_Core!FMallocTBB::Realloc() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\core\private\hal\malloctbb.cpp:99]
UE4Editor_Core!FHeapAllocator::ForAnyElementType::ResizeAllocation() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\core\public\containers\containerallocationpolicies.h:357]
UE4Editor_nantVrDemo_1494!TArray<wchar_t,FDefaultAllocator>::CopyToEmpty<wchar_t,FDefaultAllocator>() [d:\program files\epic games\4.11\engine\source\runtime\core\public\containers\array.h:2416]
UE4Editor_nantVrDemo_1494!AHospText::BuildHospString() [d:
ant-vr-demo
ant-vr-demo 4.11 - 2\source
antvrdemo\hosptext.cpp:99]
UE4Editor_nantVrDemo_1494!AHospText::UpdateDisplay() [d:
ant-vr-demo
ant-vr-demo 4.11 - 2\source
antvrdemo\hosptext.cpp:65]
UE4Editor_Engine!FTimerUnifiedDelegate::Execute() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\engine\public imermanager.h:38]
UE4Editor_Engine!FTimerManager::Tick() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\engine\private imermanager.cpp:483]
UE4Editor_Engine!UWorld::Tick() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\engine\private\leveltick.cpp:1236]
UE4Editor_UnrealEd!UEditorEngine::Tick() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\editor\unrealed\private\editorengine.cpp:1356]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\editor\unrealed\private\unrealedengine.cpp:370]
UE4Editor!FEngineLoop::Tick() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\launch\private\launchengineloop.cpp:2644]
UE4Editor!GuardedMain() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\launch\private\launch.cpp:142]
UE4Editor!GuardedMainWrapper() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\launch\private\windows\launchwindows.cpp:200]
UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:264]
kernel32
ntdll

looks like you might be derefeferencing a null pointer in BuildHospString

Haha. Thnx for the video. But why would the pointer rest ever become null? It was created in the BeginPlay() then shouldn’t it last for the duration of the game?
Also, how do I find this thread in the future, without having to search my username?
rest->GetResult() just gets the private FString in the object pointed to by rest and as I mentioned previously, I get that string but the crash happens after 30 seconds or so giving me that crash report.
Appreciate the help!

I’m assuming you didn’t set a UPROPERTY for the rest member and its getting garbage collected. If you did already add a UPROPERTY for it, just pastebin your header file and I’ll take a look at it.

I believe you also need to set an outer for the new object. The default is the Transient package but you a want it to be set the owner of the property, so the first parameter should be this.

This might be it! I will try this and let you know. Thank you very much for the support as I am a complete newbie with the Unreal API.

Will try this as well! Thanks!

It worked! I didn’t have the UPROPERTY() but after adding it, and placing this in the argument for initialization, solved the issue. I wish I could contribute back to you guys haha.
Thank you once again!