Browse Source

Merge pull request #12511 from sanikoyes/pr-fix-tabs-crash

Fix crash when click an empty tabs container
Rémi Verschelde 7 years ago
parent
commit
60df8db401
1 changed files with 7 additions and 0 deletions
  1. 7 0
      scene/gui/tab_container.cpp

+ 7 - 0
scene/gui/tab_container.cpp

@@ -90,6 +90,10 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
 			return;
 			return;
 		}
 		}
 
 
+		// Do not activate tabs when tabs is empty
+		if (get_tab_count() == 0)
+			return;
+
 		Vector<Control *> tabs = _get_tabs();
 		Vector<Control *> tabs = _get_tabs();
 
 
 		// Handle navigation buttons.
 		// Handle navigation buttons.
@@ -298,6 +302,8 @@ void TabContainer::_notification(int p_what) {
 }
 }
 
 
 int TabContainer::_get_tab_width(int p_index) const {
 int TabContainer::_get_tab_width(int p_index) const {
+
+	ERR_FAIL_INDEX_V(p_index, get_tab_count(), 0);
 	Control *control = Object::cast_to<Control>(_get_tabs()[p_index]);
 	Control *control = Object::cast_to<Control>(_get_tabs()[p_index]);
 	if (!control || control->is_set_as_toplevel())
 	if (!control || control->is_set_as_toplevel())
 		return 0;
 		return 0;
@@ -669,6 +675,7 @@ void TabContainer::_bind_methods() {
 TabContainer::TabContainer() {
 TabContainer::TabContainer() {
 
 
 	first_tab_cache = 0;
 	first_tab_cache = 0;
+	last_tab_cache = 0;
 	buttons_visible_cache = false;
 	buttons_visible_cache = false;
 	tabs_ofs_cache = 0;
 	tabs_ofs_cache = 0;
 	current = 0;
 	current = 0;