Browse Source

Cleans up properties referring to a data source when the DataSource object is destroyed, fixes #137

David Wimsey 11 years ago
parent
commit
fea7fa35bc
1 changed files with 13 additions and 9 deletions
  1. 13 9
      Source/Controls/ElementDataGridRow.cpp

+ 13 - 9
Source/Controls/ElementDataGridRow.cpp

@@ -61,6 +61,7 @@ ElementDataGridRow::~ElementDataGridRow()
 	if (data_source)
 	{
 		data_source->DetachListener(this);
+		data_source = NULL;
 	}
 }
 
@@ -109,8 +110,11 @@ int ElementDataGridRow::GetDepth()
 
 void ElementDataGridRow::SetDataSource(const Rocket::Core::String& data_source_name)
 {
-	if (data_source)
+	if (data_source != NULL)
+	{
 		data_source->DetachListener(this);
+		data_source = NULL;
+	}
 
 	if (ParseDataSource(data_source, data_table, data_source_name))
 	{
@@ -245,13 +249,13 @@ ElementDataGrid* ElementDataGridRow::GetParentGrid()
 	return parent_grid;
 }
 
-void ElementDataGridRow::OnDataSourceDestroy(DataSource* ROCKET_UNUSED_PARAMETER(data_source))
+void ElementDataGridRow::OnDataSourceDestroy(DataSource* data_source)
 {
-	ROCKET_UNUSED(data_source);
-
-	data_source->DetachListener(this);
-	data_source = NULL;
-
+	if(data_source != NULL)
+	{
+		data_source->DetachListener(this);
+		data_source = NULL;
+	}
 	RemoveChildren();
 }
 
@@ -286,7 +290,7 @@ void ElementDataGridRow::RefreshRows()
 	RemoveChildren();
 
 	// Load the children from the data source.
-	if (data_source)
+	if (data_source != NULL)
 	{
 		int num_rows = data_source->GetNumRows(data_table);
 		if (num_rows > 0)
@@ -370,7 +374,7 @@ void ElementDataGridRow::AddChildren(int first_row_added, int num_rows_added)
 
 	// We need to make a row for each new child, then pass through the cell
 	// information and the child's data source (if one exists.)
-	if (data_source)
+	if (data_source != NULL)
 	{
 		for (int i = 0; i < num_rows_added; i++)
 		{