Fixed crash when setting a filter while the game is refreshing the server list

This commit is contained in:
juanjp600
2017-12-03 20:33:20 -03:00
parent f8e5a4f7ab
commit 4a1eea8c30
3 changed files with 25 additions and 48 deletions
@@ -28,19 +28,11 @@ namespace Barotrauma
if (!Visible) return; if (!Visible) return;
if (ComponentsToUpdate.Contains(this)) return; if (ComponentsToUpdate.Contains(this)) return;
ComponentsToUpdate.Add(this); ComponentsToUpdate.Add(this);
try List<GUIComponent> fixedChildren = new List<GUIComponent>(children);
foreach (GUIComponent c in fixedChildren)
{ {
List<GUIComponent> fixedChildren = new List<GUIComponent>(children); c.AddToGUIUpdateList();
foreach (GUIComponent c in fixedChildren)
{
c.AddToGUIUpdateList();
}
}
catch (Exception e)
{
DebugConsole.NewMessage("Error in AddToGUIUPdateList! GUIComponent runtime type: "+this.GetType().ToString()+"; children count: "+children.Count.ToString(),Color.Red);
throw;
} }
} }
@@ -437,22 +429,14 @@ namespace Barotrauma
} }
}*/ }*/
try //use a fixed list since children can change their order in the main children list
//TODO: maybe find a more efficient way of handling changes in list order
List<GUIComponent> fixedChildren = new List<GUIComponent>(children);
foreach (GUIComponent c in fixedChildren)
{ {
//use a fixed list since children can change their order in the main children list if (!c.Visible) continue;
//TODO: maybe find a more efficient way of handling changes in list order c.Update(deltaTime);
List<GUIComponent> fixedChildren = new List<GUIComponent>(children);
foreach (GUIComponent c in fixedChildren)
{
if (!c.Visible) continue;
c.Update(deltaTime);
}
}
catch (Exception e)
{
DebugConsole.NewMessage("Error in Update! GUIComponent runtime type: " + this.GetType().ToString() + "; children count: " + children.Count.ToString(), Color.Red);
throw;
} }
} }
@@ -259,29 +259,21 @@ namespace Barotrauma
if (!Visible) return; if (!Visible) return;
if (ComponentsToUpdate.Contains(this)) return; if (ComponentsToUpdate.Contains(this)) return;
ComponentsToUpdate.Add(this); ComponentsToUpdate.Add(this);
try List<GUIComponent> fixedChildren = new List<GUIComponent>(children);
int lastVisible = 0;
for (int i = 0; i < fixedChildren.Count; i++)
{ {
List<GUIComponent> fixedChildren = new List<GUIComponent>(children); if (fixedChildren[i] == frame) continue;
int lastVisible = 0;
for (int i = 0; i < fixedChildren.Count; i++) if (!IsChildVisible(fixedChildren[i]))
{ {
if (fixedChildren[i] == frame) continue; if (lastVisible > 0) break;
continue;
if (!IsChildVisible(fixedChildren[i]))
{
if (lastVisible > 0) break;
continue;
}
lastVisible = i;
fixedChildren[i].AddToGUIUpdateList();
} }
}
catch (Exception e) lastVisible = i;
{ fixedChildren[i].AddToGUIUpdateList();
DebugConsole.NewMessage("Error in AddToGUIUpdateList! GUIComponent runtime type: " + this.GetType().ToString() + "; children count: " + children.Count.ToString(), Color.Red);
throw;
} }
if (scrollBarEnabled && !scrollBarHidden) scrollBar.AddToGUIUpdateList(); if (scrollBarEnabled && !scrollBarHidden) scrollBar.AddToGUIUpdateList();
@@ -124,9 +124,10 @@ namespace Barotrauma
private void FilterServers() private void FilterServers()
{ {
serverList.RemoveChild(serverList.FindChild("noresults")); serverList.RemoveChild(serverList.FindChild("noresults"));
foreach (GUIComponent child in serverList.children) foreach (GUIComponent child in serverList.children)
{ {
if (!(child.UserData is ServerInfo)) continue;
ServerInfo serverInfo = (ServerInfo)child.UserData; ServerInfo serverInfo = (ServerInfo)child.UserData;
child.Visible = child.Visible =