From 4a1eea8c30b3608821e787c8d4a4346dfe9e09ac Mon Sep 17 00:00:00 2001 From: juanjp600 Date: Sun, 3 Dec 2017 20:33:20 -0300 Subject: [PATCH] Fixed crash when setting a filter while the game is refreshing the server list --- .../Source/GUI/GUIComponent.cs | 38 ++++++------------- .../BarotraumaClient/Source/GUI/GUIListBox.cs | 32 ++++++---------- .../Source/Screens/ServerListScreen.cs | 3 +- 3 files changed, 25 insertions(+), 48 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUIComponent.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUIComponent.cs index 318ecf8b9..c4ac9c6bd 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/GUIComponent.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/GUIComponent.cs @@ -28,19 +28,11 @@ namespace Barotrauma if (!Visible) return; if (ComponentsToUpdate.Contains(this)) return; ComponentsToUpdate.Add(this); - - try + + List fixedChildren = new List(children); + foreach (GUIComponent c in fixedChildren) { - List fixedChildren = new List(children); - 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; + c.AddToGUIUpdateList(); } } @@ -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 fixedChildren = new List(children); + foreach (GUIComponent c in fixedChildren) { - //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 fixedChildren = new List(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; + if (!c.Visible) continue; + c.Update(deltaTime); } } diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUIListBox.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUIListBox.cs index 1ffd0eb98..b1cd60307 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/GUIListBox.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/GUIListBox.cs @@ -259,29 +259,21 @@ namespace Barotrauma if (!Visible) return; if (ComponentsToUpdate.Contains(this)) return; ComponentsToUpdate.Add(this); - - try + + List fixedChildren = new List(children); + int lastVisible = 0; + for (int i = 0; i < fixedChildren.Count; i++) { - List fixedChildren = new List(children); - int lastVisible = 0; - for (int i = 0; i < fixedChildren.Count; i++) + if (fixedChildren[i] == frame) continue; + + if (!IsChildVisible(fixedChildren[i])) { - if (fixedChildren[i] == frame) continue; - - if (!IsChildVisible(fixedChildren[i])) - { - if (lastVisible > 0) break; - continue; - } - - lastVisible = i; - fixedChildren[i].AddToGUIUpdateList(); + if (lastVisible > 0) break; + continue; } - } - catch (Exception e) - { - DebugConsole.NewMessage("Error in AddToGUIUpdateList! GUIComponent runtime type: " + this.GetType().ToString() + "; children count: " + children.Count.ToString(), Color.Red); - throw; + + lastVisible = i; + fixedChildren[i].AddToGUIUpdateList(); } if (scrollBarEnabled && !scrollBarHidden) scrollBar.AddToGUIUpdateList(); diff --git a/Barotrauma/BarotraumaClient/Source/Screens/ServerListScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/ServerListScreen.cs index e0fe5e227..970419f3a 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/ServerListScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/ServerListScreen.cs @@ -124,9 +124,10 @@ namespace Barotrauma private void FilterServers() { serverList.RemoveChild(serverList.FindChild("noresults")); - + foreach (GUIComponent child in serverList.children) { + if (!(child.UserData is ServerInfo)) continue; ServerInfo serverInfo = (ServerInfo)child.UserData; child.Visible =