-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Remove include of "bionics.h" from "character.h". #22528
Conversation
… it. They usually only work the bionic id (a `string_id`), and that does not need a definition from "bionics.h".
Changes `Character::my_bionics` to be a `copyable_uniqe_ptr<bionic_collection>`. `bionic_collection` is a simple wrapper for `std::vector<bionic>`, defined in "bionics.h". It can be forward declared, without defining the `bionic` class, `std::vector<bionic>` can't be forward declared without defining the `bionic` class. Moves the definition of the destructor of `Character` into the cpp file because it implicitly requires the destructor of `bionics_collection` to be visible.
/usr/include/c++/7.2.0/bits/unique_ptr.h:322: typename std::add_lvalue_reference<_Tp>::type std::unique_ptr<_Tp, _Dp>::operator*() const [with _Tp = bionic_collection; _Dp = std::default_delete<bionic_collection>; typename std::add_lvalue_reference<_Tp>::type = bionic_collection&]: Assertion 'get() != pointer()' failed. backtrace from gdb: |
(gdb) f 4 So... the unique ptr isn't initialized. |
@@ -602,7 +605,7 @@ class Character : public Creature, public visitable<Character> | |||
item weapon; | |||
item ret_null; // Null item, sometimes returns by weapon() etc | |||
|
|||
std::vector<bionic> my_bionics; | |||
copyable_unique_ptr<bionic_collection> my_bionics; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This here is the problem I think, the vector was default contructed, but the unique_ptr is constructed empty, it just needs a new default constructed bionic_collection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all good, added my_bionics.reset( new bionic_collection() );
to the end of the Character constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sorry. I forgot that. Somehow I assumed the wrapper would create the pointer automatically. May need to add something like this.
Changes
Character::my_bionics
to be acopyable_uniqe_ptr<bionic_collection>
.bionic_collection
is a simple wrapper forstd::vector<bionic>
, defined in "bionics.h".It can be forward declared, without defining the
bionic
class (std::vector<bionic>
can't be forward declared without defining thebionic
class)."bionics.h" used to be included (directly/indirectly) by 103 cpp files, no it's only included by 11 cpp files.