Check for widget != nullptr before add/remove child.

This commit is contained in:
Jared Boone 2015-10-16 19:34:22 -07:00
parent dab801e167
commit dc30911e0f

View File

@ -304,10 +304,12 @@ void View::paint(Painter& painter) {
} }
void View::add_child(Widget* const widget) { void View::add_child(Widget* const widget) {
if( widget->parent() == nullptr ) { if( widget ) {
widget->set_parent(this); if( widget->parent() == nullptr ) {
children_.push_back(widget); widget->set_parent(this);
widget->set_dirty(); children_.push_back(widget);
widget->set_dirty();
}
} }
} }
@ -318,11 +320,13 @@ void View::add_children(const std::vector<Widget*>& children) {
} }
void View::remove_child(Widget* const widget) { void View::remove_child(Widget* const widget) {
children_.erase(std::remove(children_.begin(), children_.end(), widget), children_.end()); if( widget ) {
dirty_screen_rect += widget->screen_rect(); children_.erase(std::remove(children_.begin(), children_.end(), widget), children_.end());
widget->set_parent(nullptr); dirty_screen_rect += widget->screen_rect();
if( dirty_screen_rect ) { widget->set_parent(nullptr);
set_dirty(); if( dirty_screen_rect ) {
set_dirty();
}
} }
} }