UProceduralMeshComponent::UpdateMeshSection c++ crash

Hello,

Calling UpdateMeshSection on a UProceduralMeshComponent, from inside of another Actor’s Tick() function, causes a crash.

Even when passing simple geometry (box), and even when passing the exact same geometry as to CreateMeshSection. I am respecting the restriction that topology must mot change for updating to work.

I am wondering what is the right way to use the UpdateMeshSection function? Since it modifies the rendering data, should I call the function only from a specific place/event, or surround the call with some thread locks?

Thanks!

Rados

I cannot reproduce it in a clean project. Something else is causing the crash in the render thread and is triggered by updating the mesh.

Hello ,

Could you post the callstack for the crash that you’re experiencing? It may have more information into what is going wrong and I may be able to use it to find similar reports.

Hi ,

I managed to reproduce the problem!

If we create An actor, then a ProceduralMeshComponent, then set that Actor to be hidden in game, then wait a bunch of frames, get back the actor into the game and in the same tick update the mesh component, we get a crash. If we wait even 1 tick after we SetHidden=false we can update it.

This may be a completely wanted behaviour, that it takes a tick for the actor to “wake up”.

I attached the project which reproduces it, at least on my machine. In the MyMainActor Tick function is where the action happens.

Cheers!
Rados

And the call stack:

[Access violation - code c0000005 (first/second chance not available)

UE4Editor_ProceduralMeshComponent!FProceduralMeshSceneProxy::UpdateSection_RenderThread()
UE4Editor_ProceduralMeshComponent!TGraphTask<`UProceduralMeshComponent::UpdateMeshSection'::`6'::EURCMacro_FProcMeshSectionUpdate>::ExecuteTask()
UE4Editor_Core!FNamedTaskThread::ProcessTasksNamedThread() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\core\private\async\taskgraph.cpp:779]
UE4Editor_Core!FNamedTaskThread::ProcessTasksUntilQuit() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\core\private\async\taskgraph.cpp:526]
UE4Editor_RenderCore!RenderingThreadMain() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\rendercore\private\renderingthread.cpp:310]
UE4Editor_RenderCore!FRenderingThread::Run() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\rendercore\private\renderingthread.cpp:417]
UE4Editor_Core!FRunnableThreadWin::Run() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\core\private\windows\windowsrunnablethread.cpp:74][1]

I was able to test it using the project you provided. The problem is the SceneProxy is null. When you hide the actor the existing scene proxy is destroyed, and when you show it again, it gets recreated but it gets recreated later in the frame/early in the next frame which is after your attempt to update the mesh section. UpdateMeshSection assumes the SceneProxy exists since it queues a render thread action against it.

I’ve put together a fix for it and appended it to another PR I have for a bugfix on the PMC. This should also solve another question I came across in the past couple days where someone was trying to call UpdateMeshSection in the actor constructor and it was crashing. This was the same problem since at that point the SceneProxy hadn’t been created.

Here’s the PR…

.com/EpicGames/UnrealEngine/pull/2351

Here’s the specific fix if you need to recreate this in your own build…

.com/EpicGames/UnrealEngine/pull/2351/commits/5ec0ad9bf0f4fbd013fc9f96e8b9c8ebe6291667

Thank you for the fix :slight_smile:

Np! glad I could help!