Closed vnepogodin closed 2 years ago
The parent detach its child. The child updates its parent pointer to nullptr. The problem happens when the detaching cause the ref count to go to zero and delete the child. One solution would be to update |parent_| to nullptr earlier.
Probably something like:
void ComponentBase::Detach() {
if (!parent_)
return;
auto it = std::find_if(std::begin(parent_->children_), //
std::end(parent_->children_), //
[this](const Component& that) { //
return this == that.get();
});
ComponentBase* parent = parent_;
parent_ = nullptr;
parent->children_.erase(it); // Might delete |this|.
}
Problem:
Getting that with valgrind. All components affected.
Expected: too see zero output related to that error from valgrind.
How to reproduce: