Browse Source

Fix for select element (drop-down list) corrupting document on remove

Michael 8 years ago
parent
commit
b6f981b069
1 changed files with 5 additions and 1 deletions
  1. 5 1
      Source/Controls/WidgetDropDown.cpp

+ 5 - 1
Source/Controls/WidgetDropDown.cpp

@@ -71,7 +71,11 @@ WidgetDropDown::WidgetDropDown(ElementFormControl* element)
 
 
 WidgetDropDown::~WidgetDropDown()
 WidgetDropDown::~WidgetDropDown()
 {
 {
-	ClearOptions();
+	// We shouldn't clear the options ourselves, as removing the element will automatically clear children.
+	//   Not always a problem, but sometimes it invalidates the layout lock in Element::RemoveChild, which results in a permanently corrupted document.
+	//   However, we do need to remove events of children.
+	for(auto& option : options)
+		option.GetElement()->RemoveEventListener("click", this);
 
 
 	parent_element->RemoveEventListener("click", this, true);
 	parent_element->RemoveEventListener("click", this, true);
 	parent_element->RemoveEventListener("blur", this);
 	parent_element->RemoveEventListener("blur", this);