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?
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.
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.
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…