BuildPatchTool crashes for RunUAT with Android -createchunkinstall

The project has most assets in chunk 0 with a single directory with a ChunkLabel causing it to be chunked separately - everything is configured as per the chunking instructions. Creating the chunked build with the command in the repro section works for IOS (though with the relevant parameter fields changed) on Mac, but BuildPatchTool crashes on exit when running on Windows to make the Android build.

The call stack for the crash is:

BuildPatchTool-Win64-Debug.exe!PureCallHandler() Line 731 C++

[External Code]

BuildPatchTool-Win64-Debug.exe!FMsg::LogV::__l5::<lambda>() Line 81 C++

BuildPatchTool-Win64-Debug.exe!FMsg::LogV(const char * File, int Line, const FName & Category, ELogVerbosity::Type Verbosity, const wchar_t * Fmt, char * Args) Line 78 C++

BuildPatchTool-Win64-Debug.exe!UE::Logging::Private::BasicLog(const FLogCategoryBase & Category, const UE::Logging::Private::FStaticBasicLogRecord * Log, …) Line 1089 C++

BuildPatchTool-Win64-Debug.exe!FPakPlatformFile::~FPakPlatformFile() Line 4484 C++

[External Code]

BuildPatchTool-Win64-Debug.exe!FModuleManager::FModuleInfo::~FModuleInfo() Line 613 C++

BuildPatchTool-Win64-Debug.exe!SharedPointerInternals::TDeleterHolder<SharedPointerInternals::DefaultDeleter<FModuleManager::FModuleInfo>,1>::InvokeDeleter<FModuleManager::FModuleInfo>(FModuleManager::FModuleInfo * Object) Line 341 C++

BuildPatchTool-Win64-Debug.exe!SharedPointerInternals::TReferenceControllerWithDeleter<FModuleManager::FModuleInfo,SharedPointerInternals::DefaultDeleter<FModuleManager::FModuleInfo>,1>::DestroyObject() Line 376 C++

[External Code]

BuildPatchTool-Win64-Debug.exe!TSparseArray<TSetElement<TTuple<FName,TSharedRef<FModuleManager::FModuleInfo,1>>>,TSparseArrayAllocator<TSizedDefaultAllocator<32>,FDefaultBitArrayAllocator>>::Empty(int ExpectedNumElements) Line 400 C++

BuildPatchTool-Win64-Debug.exe!TSparseArray<TSetElement<TTuple<FName,TSharedRef<FModuleManager::FModuleInfo,1>>>,TSparseArrayAllocator<TSizedDefaultAllocator<32>,FDefaultBitArrayAllocator>>::~TSparseArray<TSetElement<TTuple<FName,TSharedRef<FModuleManager::FModuleInfo,1>>>,TSparseArrayAllocator<TSizedDefaultAllocator<32>,FDefaultBitArrayAllocator>>() Line 85 C++

[External Code]

BuildPatchTool-Win64-Debug.exe!FModuleManager::~FModuleManager() Line 177 C++

> BuildPatchTool-Win64-Debug.exe!TOptional<FModuleManager>::Reset() Line 232 C++

[External Code]

And it actually crashes after BuildPatchTool’s main returns 0 (success) and the OS wrapper calls exit(main_result);

Steps to Reproduce
Project with at least two chunks, RunUAT roughly like so:

.\RunUAT.bat BuildCookRun -nop4 -cook -project={project} -platform=Android -cookflavor=ASTC -stage -archive -package -build -pak -compressed -prereqs -archivedirectory=“{outdir}” -manifests -clientconfig=“Development” -createchunkinstall -chunkinstalldirectory=“{outdir}\CDNChunks” -chunkinstallversion=1.0

To test the crash in debugger, can run BuildPatchTool with the roughly these parameters:

-BuildRoot=“{chunksdir}\Android_ASTC\1\pakchunk{chunknum}” -CloudDir={outdir}\CDNChunks\Android_ASTC\CloudDir" -AppID=1 -AppName=“{projectname}_pakchunk{chunknum}” -BuildVersion=“1” -AppLaunch=“” -AppArgs=“” -custom=“bIsPatch=false” -customint=“ChunkID={chunknum}” -customint=“PakReadOrdering=0” -stdout

I can’t provide a full repro because it would require sharing my company’s confidential code.

I have been able to unblock our pipline by manually calling FModuleManager::TearDown(); right before the return code is returned in BuildPatchToolMain, but I’m not sure if this is the right approach.

Hello!

The change you propose seems fine. The source of the crash seems to be an improper order of destruction. Tearing down the module manager should enforce a proper order of destruction at the modules level.

I reached to the team that own the BuildPatchTool to get their input and so they can add the fix for later releases.

Regards,

Martin