More Crash Avoidance
Part 1: Delegates
Delegates are like little event messengers that get bound to function pointers. We use them a lot, they signal deaths, animation queues, UI events. They can be an extremely useful way to create systems that react to user input and in game events.
They can also do this:
This is not a desirable outcome. Stuff like this occurs when something that's been dynamically allocated to memory decides to change its location and disappear, even when other elements of your program reference where it used to be. The code made a promise, and when that promise suddenly cant be fulfilled anymore your output window starts looking pretty red.
Why did this happen?
Here, the problem was my UI wasn't allowing delegates to be released when it disappeared. I was also destroying the entire pause menu every time it disappeared, so unreal was stacking "promises" on already promised memory to rebind each delegate when the pause button was pressed again. The more the user opened the pause menu, the more and more "broken promises" kept stacking up. This is a memory leak. A bunch of junk memory piling up that thinks it's reserved but actually isn't organized by the program anymore, meaning unreal needs to freeze, dump a bunch of memory away, and then try and pick back up on every repeated press of the pause menu.
Part 2: also delegates
The solution is not having spaghetti for brains. It was solved in a few simple steps.
A: Stop demolishing the pause menu every time the game is resumed. The pause menu needs to be persistent, it does have to save the state of certain elements and cannot be re-created every time it's needed. The below code used to just add the pause menu to viewport and then demolish the whole thing when the resume button was clicked.
B: build a real destructor to clean up all of the extra memory. The solution above does not work on it's own, if any of the below variables still have their resources allocated when the game needs to load a new context, you get a crash.
And that's pretty much it. Now you can spam the pause button without ever having to worry about freezes or crashes.
Wave Breakers – Strategy Hybrid Tower Defense
Defend island fortresses in a hybrid FPS & strategy tower defense with NPC crews, upgrades, and epic sea battles.
Status | In development |
Authors | SyntaxSurfers, ArmchairBinkie, MercxZ, JoseanRodriguez, nomadochi |
Genre | Strategy, Action |
Tags | base-defense, hybrid, Tower Defense, Unreal Engine |
More posts
- I can't see without my debug lines! *Velma voice*1 day ago
- Phantom Tower Bug1 day ago
- Lines and Boxes: Everything has its place8 days ago
- When Your Tower Decides to Self‑Destruct8 days ago
- How We Stopped Our Game from Crashing12 days ago
- Gotta go fast, But not too fast!12 days ago
- The Internet Lies To You15 days ago
Leave a comment
Log in with itch.io to leave a comment.