Random crash in a procedurally generated world
During one of our Unreal Engine-based projects, which featured a procedurally generated world, I needed to fix a crash that was reproducible only on the PS5. Fortunately, I managed to reproduce it myself.
The original description was quite vague, and I spent several days trying to replicate the issue. Initially, the crash seemed random, making it difficult to determine if a fix is effective.
Because the world was procedurally generated, the same seed would produce the same world. Fun fact – to trigger the crash in the world with mushrooms, after spawning, you had to walk around and repeatedly look at the mushrooms from different angles and in different directions.
Knowing the seed and scenario that reproduced the crash within minutes made analyzing it easier. The call stacks pointed to custom VFX tied to those mushrooms, which used a pool so effects could be reused, but sometimes got deallocated. Upon deeper investigation, it turned out the effects were being garbage-collected unexpectedly. How was it possible?
Most of the code was correct and followed best practices by loading assets asynchronously and referencing them with TSoftObjectPtr to avoid requiring them at map load. However, soft references don’t prevent garbage collection; so-called “hard references” are needed. Upon reviewing the code comments, it seems an intern programmer who is no longer with the company attempted this without a full understanding, trying to use smart pointers instead.
The fix was simple: adding UCLASS and UPROPERTY macros to guide the Garbage Collection system properly. After this, the issue vanished.
In summary, the crash has affected all platforms, but it has only occurred coincidentally on the PS5. When memory is garbage-collected unexpectedly, accessing it can cause undefined behavior.