Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

The terrible C++ garbage collector crash by improper lambda usage -- UE C++ Tutorial

The terrible C++ garbage collector crash by improper lambda usage -- UE C++ Tutorial

6,963 0


Perhaps the most common way someone learning to write C++ in Unreal accidentally crashes the game.

Without safe mark up, you can create a ticking time bomb for a crash. C++ can be dangerous if not careful. Blueprint ensures this type of situation isn't possible, but with C++ it is on you to ensure your safely accessing and protecting your memory. By putting the macro UPROPERTY() above your variables to unreal types, the GC becomes aware of the pointer and will manage it. But without it, you create a situation where the GC will free the object, but be unaware to update the pointer to nullptr. Meaning you will have a dangling pointer. At best this null pointer will crash the game. At worst, it will corrupt memory and the game will keep on running with invalid memory. Wrecking incomprehensible and inconsistent issues on the game with undefined behavior.

Recommended resources

Game Engines

See full guide
Unreal Engine 5 Best Practices cover
Editor pick

Unreal Engine 5 Best Practices

Amazon · Book

Written by multi-award-winning Unreal generalist Tyson J. Butler-Boschma, Founder and Creative Director of Toybox Games Studios, this book addresses common challenges you face when advancing your expertise in lighting, environment design, and cinematic storytelling.

GameDev.net may earn a commission if you purchase through these links. This helps fund the site at no extra cost to you.

GameDev.net may earn a commission if you purchase through these links. This helps fund the site at no extra cost to you.

Discussion

Loading comments...