Crash in Stats thread on 4.16

Hey guys,

I have an old project using UE 4.16.0 that crashes at startup. The crash occurs in Development configuration and doesn’t occur in Debug so this looks like a kind of uninitialized memory issue.

  • Project: UE4Game
  • Platform: Win32
  • Configuration: Development
  • LinkType: Modular

Here is the call stack (copied from VS):

[Inline Frame] UE4-Core.dll!FWindowsPlatformMisc::DebugBreak() Line 57 C++
[Inline Frame] UE4-Core.dll!TArray<FStatPacket *,FDefaultAllocator>::CheckAddress(FStatPacket * const *) Line 1357 C++
[Inline Frame] UE4-Core.dll!TArray<FStatPacket *,FDefaultAllocator>::Add(FStatPacket * const &) Line 1794 C++
[Inline Frame] UE4-Core.dll!FStatsThread::StatMessage(FStatPacket * Packet) Line 957 C++
[Inline Frame] UE4-Core.dll!FStatMessagesTask::DoTask(ENamedThreads::Type) Line 996 C++
UE4-Core.dll!TGraphTask::ExecuteTask(TArray<FBaseGraphTask *,FDefaultAllocator> & NewTasks, ENamedThreads::Type CurrentThread) Line 883 C++
[Inline Frame] UE4-Core.dll!FBaseGraphTask::Execute(TArray<FBaseGraphTask *,FDefaultAllocator> & CurrentThread, ENamedThreads::Type) Line 488 C++
UE4-Core.dll!FNamedTaskThread::ProcessTasksNamedThread(int QueueIndex, bool bAllowStall) Line 954 C++
UE4-Core.dll!FNamedTaskThread::ProcessTasksUntilQuit(int QueueIndex) Line 701 C++
UE4-Core.dll!FTaskGraphImplementation::ProcessThreadUntilRequestReturn(ENamedThreads::Type CurrentThread) Line 1758 C++
UE4-Core.dll!FStatsThread::Run() Line 863 C++
UE4-Core.dll!FRunnableThreadWin::Run() Line 76 C++
UE4-Core.dll!FRunnableThreadWin::GuardedRun() Line 25 C++
UE4-Core.dll!FRunnableThreadWin::_ThreadProc(void * pThis) Line 78 C++

UPD: There is another crash that seems to be related:

[Inline Frame] UE4-Core.dll!FWindowsPlatformMisc::DebugBreak() Line 57 C++
UE4-Core.dll!FGenericPlatformMemory::OnOutOfMemory(unsigned __int64 Size, unsigned int Alignment) Line 170 C++
[Inline Frame] UE4-Core.dll!FMallocBinned2::Private::OutOfMemory(unsigned __int64) Line 271 C++
UE4-Core.dll!FMallocBinned2::MallocExternal(unsigned long Size, unsigned int Alignment) Line 688 C++
UE4-Core.dll!FMallocBinned2::ReallocExternal(void * Ptr, unsigned long NewSize, unsigned int Alignment) Line 735 C++
UE4-Core.dll!FMallocBinned2::Realloc(void * Ptr, unsigned long NewSize, unsigned int Alignment) Line 432 C++
UE4-Core.dll!FMallocPoisonProxy::Realloc(void * Ptr, unsigned long NewSize, unsigned int Alignment) Line 67 C++
UE4-Core.dll!FMemory::Realloc(void * Original, unsigned long Count, unsigned int Alignment) Line 34 C++
[Inline Frame] UE4-Core.dll!FHeapAllocator::ForAnyElementType::ResizeAllocation(int) Line 385 C++
UE4-Core.dll!TArray<FStatMessage,FDefaultAllocator>::ResizeGrow(int OldNum) Line 2267 C++
[Inline Frame] UE4-Core.dll!TArray<FStatMessage,FDefaultAllocator>::AddUninitialized(int) Line 1221 C++
UE4-Core.dll!operator new<FStatMessage,FDefaultAllocator>(unsigned int Size, TArray<FStatMessage,FDefaultAllocator> & Array) Line 2825 C++
UE4-Core.dll!FStartupMessages::AddMetadata(FName InStatName, const wchar_t * InStatDesc, const char * InGroupName, const char * InGroupCategory, const wchar_t * InGroupDesc, bool bShouldClearEveryFrame, EStatDataType::Type InStatType, bool bCycleStat, FWindowsPlatformMemory::EMemoryCounterRegion InMemoryRegion) Line 325 C++
UE4-Core.dll!FThreadSafeStaticStatBase::DoSetup(const char * InStatName, const wchar_t * InStatDesc, const char * InGroupName, const char * InGroupCategory, const wchar_t * InGroupDesc, bool bDefaultEnable, bool bShouldClearEveryFrame, EStatDataType::Type InStatType, bool bCycleStat, FWindowsPlatformMemory::EMemoryCounterRegion InMemoryRegion) Line 352 C++
[Inline Frame] UE4-Core.dll!FThreadSafeStaticStatInner<FStatsThreadState::FindOrAddMetaData'::5’::FStat_STAT_FSimpleDelegateGraphTask_StatsGroupToGame,1>::GetStatId() Line 1688 C++
UE4-Core.dll!FStatsThreadState::FindOrAddMetaData(const FStatMessage & Item) Line 1745 C++
UE4-Core.dll!FStatsThreadState::ProcessMetaDataOnly(TArray<FStatMessage,FDefaultAllocator> & Data) Line 804 C++
UE4-Core.dll!FStatsThread::Tick() Line 917 C++
[Inline Frame] UE4-Core.dll!FStatsThread::StatMessage(FStatPacket * Packet) Line 960 C++
[Inline Frame] UE4-Core.dll!FStatMessagesTask::DoTask(ENamedThreads::Type) Line 996 C++
UE4-Core.dll!TGraphTask::ExecuteTask(TArray<FBaseGraphTask *,FDefaultAllocator> & NewTasks, ENamedThreads::Type CurrentThread) Line 886 C++
[Inline Frame] UE4-Core.dll!FBaseGraphTask::Execute(TArray<FBaseGraphTask *,FDefaultAllocator> & CurrentThread, ENamedThreads::Type) Line 488 C++
UE4-Core.dll!FNamedTaskThread::ProcessTasksNamedThread(int QueueIndex, bool bAllowStall) Line 954 C++
UE4-Core.dll!FNamedTaskThread::ProcessTasksUntilQuit(int QueueIndex) Line 701 C++
UE4-Core.dll!FTaskGraphImplementation::ProcessThreadUntilRequestReturn(ENamedThreads::Type CurrentThread) Line 1758 C++
UE4-Core.dll!FStatsThread::Run() Line 863 C++
UE4-Core.dll!FRunnableThreadWin::Run() Line 76 C++
UE4-Core.dll!FRunnableThreadWin::GuardedRun() Line 25 C++
UE4-Core.dll!FRunnableThreadWin::_ThreadProc(void * pThis) Line 78 C++

Which of two will appear seems to be random, but one of them always does.