Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in FRealtimeMeshSectionGroupSimple on async rebuild of collisions #290

Open
OriginalAxle opened this issue Nov 22, 2024 · 0 comments

Comments

@OriginalAxle
Copy link

OriginalAxle commented Nov 22, 2024

Description:

There appears to be a memory leak in the async update of collision meshes, specifically in URealtimeMeshSimple. Trace file captures (screenshots attached to this report) are available upon request (Associated bug is in the bug report feed and help channels)

Proconditions:

Given a cube mesh where each side is subdivided into four quadrants.
and Collision + Mesh builder:

RealtimeMesh = RealtimeMeshComponent->InitializeRealtimeMesh();

Mesh builder
meshBuilder = TSharedPtr<TRealtimeMeshBuilderLocal<uint32, FPackedNormal, FVector2DHalf, 1>>(new TRealtimeMeshBuilderLocal<uint32, FPackedNormal, FVector2DHalf, 1>(streamedMeshData));

meshBuilder->EnableTangents();
meshBuilder->EnableTexCoords();
meshBuilder->EnableColors();
meshBuilder->EnablePolyGroups();

Config definition
FRealtimeMeshCollisionConfiguration CollisionConfig;
CollisionConfig.bUseAsyncCook = false; <------- IF SET TO TRUE, PROBLEM HAPPENS
CollisionConfig.bUseComplexAsSimpleCollision = true;
CollisionConfig.bShouldFastCookMeshes = false;
CollisionConfig.bDeformableMesh = false;
CollisionConfig.bFlipNormals = false;


Steps to reproduce:

  1. Instantiate the mesh

groupKey = FRealtimeMeshSectionGroupKey::Create(0, FName("chunkMesh"));
RealtimeMesh->CreateSectionGroup(groupKey, streamedMeshData);
RealtimeMesh->SetupMaterialSlot(0, "PrimaryMaterial", voxelManager->voxelMaterial);
PolyGroup0Key = FRealtimeMeshSectionKey::CreateForPolyGroup(groupKey, 0);
RealtimeMesh->UpdateSectionConfig(PolyGroup0Key, RealtimeMesh->GetSectionConfig(PolyGroup0Key), true);

  1. Modify the mesh (remove a sub division)
  2. Check memory

Important notes:

  1. Mesh collision memory scales with mesh complexity, causing simple test cases to not adequately report the memory leak
  2. I have attached in the original post the images of unreal insights trace and some code showing the problem happening at runtime
  3. Problem does not occur when the RealtimeMeshComponent is reinitialized at runtime implying the problem does not occur in component destruction

UPDATE 1:
After some additional tracking there appears to be another reporting of the issue here

UPDATE 2:
Was unable to get the collision mesh to properly generate when async generation flag was false in collision config

Associated trace screenshot
50_Mem_Leak_Debug_Printout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant