The WorldPartitionBuilder for PCG calls FinishAllCompilation mutliple times, which leads to call MeshPaintVirtualTexture::AddAllocatedVT from AcquireAllocatedVT_RenderThread. The commandlet (started with -AllowCommandletRendering) does not ever FVirtualTextureSystem::Get().CallPendingCallbacks(), so the callback added from GetRendererModule().AddVirtualTextureProducerDestroyedCallback that is supposed to clean the AllocatedVTs is never called. This leads to have the global TSet<IAllocatedVirtualTexture*> AllocatedVTs; to grow and eventually the ensure(!bAlreadyInSet); is triggered because a new IAllocatedVirtualTexture was created at the memory adress of a previous one that is no longer valid, but hang in the array.
In brief, what would be the right way to make sure the MeshPaintVirtualTexture::AllocatedVTs is cleared properly in a commandlet? Thanks in advance!
Thanks for reaching out and the thorough code analysis. I could not reproduce the issue, but examined the relevant code parts and order of events and I think your proposed fix is a good solution (given it only gets called when the commandlet runs) if it works around the issue of triggering the ensure(!bAlreadyInSet).
Please let me know if the issue reappears, or if you can find reliable repro conditions which could help debug this further.