HISM UpdateInstanceTransform crashes (with repro)
For a few major versions now, HISM (Hierarchical Instanced Static Mesh) has been particularly crash-prone during run-time updates, i.e. when UpdateInstanceTransform, AddInstance, etc are used on a HISM component after the game has begun. The crash typically happens in the rendering thread due to a HISM "ClusterTree" being invalid.
After chasing this for ages I finally have a clean simple repro project that demonstrates exactly what triggers this HISM crash.
Run the sample project, it should crash within 8-10 seconds. If not, just wait a bit or try a few times again. This bug is timing related so it behaves a little differently each time you run it. The relevant code is in HISMCrashSimulator.cpp's Tick function.
HISM is likely to crash whenever UpdateInstanceTransform is called with a location that is exactly the same as the current location of the instance. Furthermore, calling AddInstanceTransform around the same time practically guarantees that the crash will happen (that's what the repro project does).
In other words, if you need to update only the scale or rotation of a HISM instance and leave the location intact (or if you simply pass the instance's current transform back to the update function) it eventually crashes and especially so if a new instance is also added at or around the same time.
The crash occurs in the rendering thread at HierarchicalInstancedStaticMeshComponent.cpp in the function UpdateInstanceTreeBoundsInternal_RenderThread. Specifically - FClusterNode* Node = &ClusterTree; which produces undefined behavior because ClusterTree's memory is invaild.
Sometimes it crashes right there, other times further ahead, but perhaps the most frightening issue of all is when it freezes the entire unreal process inside some WinEvent thread wait routine after which it is very difficult to even come out and close the program!
HISM's code treats "In-place-updates" (i.e. location unchanged) as a special scenario, this is where the issues manifest.
So the workaround is to add a tiny offset to the location so we can bypass that scenario, like this:
Obviously far from ideal, but until there's a fix I really needed a way to stabilize my release builds so I could move forward and perhaps others using HISM may be in a similar situation as well.
I hope this report helps in fixing the issue!
HISM is one of my favorite features in Unreal Engine and the possibilities are endless when you add dynamic behaviors to it (that's where the tricky bugs usually come in). I hope to see HISM become even more awesome over time!
Firstly I would like to preface by saying, by updating these HISMC on EventTick, it needs to run on every single game cycle. That means you can't even draw a frame until the BP is done doing whatever you told it to do, which in your case add another HISMC. Secondly, you are using a for loop to also update the number of instances per tick, which is equally as dangerous. Remember that when making anything on the Event Graph, do your very best to keep things event-based, rather than being driven by Tick and you'll be fine.
Instead of running on EventTick, try using a Timeline and set it to 'Auto-Play' which you can then set a custom time dilation to control when your HISMC updates. This keeps your blueprints needing to wait for the event tick to complete before being able to tick again. With that said, I was able to load your project and did not experience a crash. Could you provide me with your 'dxdiag' so I can take a look at your system specifications?
Once you attempt the suggested alterations to how you call the HISMC to be updated, let me know if you still experience the same issues/crash and we can continue with the troubleshooting process.
answered May 06 '16 at 08:23 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here