Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.6] Use shared_ptr for library entities #4025

Merged
merged 3 commits into from
May 30, 2024

Conversation

IvanSavenko
Copy link
Member

This change removes manual memory management from VCMI_Lib classes (handlers) and replaces raw pointers with shared_ptr.
Effectively independent part of #3997.

Originally intended to use unique_ptr instead, but that turned out to be more complex & resulted in less readable code. Kind of wish there was smart pointer which defines only one 'owner' and possible 'borrowers' (other than raw pointers or weak_ptr which can be easily promoted to shared_ptr).

List of changes:

  • All classes that derive from IHandlerBase (hero/creature/town/etc handlers) now use shared_ptr as storage for objects
  • Removed unused and non-functional since 1.4 'update entity' logic from VLC classes
  • Removed some cases where game would get non-const pointer to VLC objects
  • Game entities are now non-copyable, to prevent subtle operations on copies
  • Reduced direct access to VLC in favor of identifiers promotion to objects

@IvanSavenko IvanSavenko merged commit 5d6470e into vcmi:develop May 30, 2024
14 checks passed
@IvanSavenko IvanSavenko deleted the shared_ptr_lib branch May 30, 2024 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant