Skip to content

MAP: Use standard smart pointers to manage memory allocation of game objects #518

@tturocy

Description

@tturocy

For very historical reasons, our handling of referring to member objects of games (via the GameObject and GameObjectPtr system) conflates two logically distinct considerations:

  • The validity of an object (that is, whether it continues to refer to a legitimate part of the game, or has been deleted at some point by some operation);
  • The reference counting of pointers to an object (to ensure memory gets deallocated correctly).

This leads to object deletion at potentially surprising times, because in GameObject there is a place where delete this is called - which is not ideal, even if it is technically legal. Without being exceptionally careful one can easily enough create a situation where an operation is attempted on an object that was deleted as part of the Invalidate() call on it.

  • Use std::shared_ptr and std::weak_ptr as appropriate to handle memory management of game component objects
  • Create a new variation on GameObjectPtr which stores a std::shared_ptr to the object, and checks for validity, but which does not have any responsibility for reference counting.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions