Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve: migrate Thing and derivatives to shared_ptr (#1592)
This is a comprehensive update affecting nearly the entire codebase, driven by a focus on memory safety. I've scrutinized constructors and destructors to identify areas incompatible with smart pointers—such as the inability to use shared_from_this() within constructors or destructors—and made appropriate changes. Notable Points: • Cylinder relationships were complex. To avoid cyclical dependencies that would hamper memory release, I've adopted a unidirectional reference strategy. Specifically, containers use std::shared_ptr for their itemList, whereas cylinders use std::weak_ptr for their parent, mitigating potential cycles. This alone is a safer alternative to using raw pointers. • "Browse Field" posed another challenge. These are dynamically generated containers that need to be player-associated but also globally tracked by the Game class. The resolution was to use std::weak_ptr within Game, allowing the reference count to drop to zero when all players exit the browse field. This necessitated a cleanup loop to remove expired weak_ptr instances, which, conveniently, could be incorporated directly into the existing Game class.
- Loading branch information