Indefinitely Allocated MeshPaintVirtualTexture in Commandlet

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!

Steps to Reproduce
This must be specific to our data, but the repro is to start the UPCGWorldPartitionBuilder.

What I ended up doing to fix the issue is to add this code:

void FRendererModule::ReleaseVirtualTexturePendingResources()

{

// START NEW CODE

if (IsRunningCommandlet() && IsAllowCommandletRendering())

FVirtualTextureSystem::Get().CallPendingCallbacks();

// END NEW CODE

FVirtualTextureSystem::Get().ReleasePendingResources();

}

Is it right?

Hi,

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.

Thanks,

Sam

Unfortunately I did not find simple repro steps. My code suggestion 100% fixes the ensure for now. Will let you know if anything else related appears.

Thanks and have a great day sir,

M

Hi,

No problem for the repro steps and thanks for sharing the fix and letting me know it fully fixes your issue.

Best regards,

Sam