From be9abd262fee5538f2fa290a95d1f3cf76893254 Mon Sep 17 00:00:00 2001 From: MrMaho Date: Sun, 27 Sep 2026 08:55:11 +0200 Subject: [PATCH] Server browser: keep the list stable between GUI passes (fixes 'Getting control 1's position' error) Co-Authored-By: Claude Opus 5.5 --- LobbyUI.cs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/LobbyUI.cs b/LobbyUI.cs index 0f7afb9..4754cbb 100644 --- a/LobbyUI.cs +++ b/LobbyUI.cs @@ -44,6 +44,8 @@ namespace MSCO bool stylesReady; Texture2D texBackground, texSidebar, texAccent, texOnline, texPending, texMuted, texRow; + List shownAll, shownServers; // Stand des letzten Layout-Durchgangs + string layoutError; GUIStyle windowBox, sidebarBox, rowBox, accentBox, pillStyle, pillMutedStyle, chipOnStyle, chipOffStyle; GUIStyle logoStyle, taglineStyle, navStyle, navActiveStyle, titleStyle, textStyle, captionStyle, fieldStyle, primaryStyle, secondaryStyle, statusStyle, tabStyle, headerCellStyle, @@ -151,7 +153,11 @@ namespace MSCO } // Server, die auf die direkte Abfrage nicht antworten (z.B. gerade geschlossen), gar nicht zeigen - List all = browser.Servers.FindAll(s => !s.Offline); + // Unity-GUI läuft in mehreren Durchgängen (Layout, Klick, Zeichnen). Die Liste nur im Layout-Durchgang + // übernehmen - ändert sie sich dazwischen (Aktualisierung im Hintergrund), bricht das Layout sonst ab + if (shownAll == null || Event.current.type == EventType.Layout) + shownAll = browser.Servers.FindAll(s => !s.Offline); + List all = shownAll; // Server-Profil (Klick auf einen Server) if (selectedServer != null) @@ -186,10 +192,13 @@ namespace MSCO GUILayout.Space(6); string search = (searchInput ?? "").Trim().ToLower(); - List servers = all.FindAll(s => - (s.RequireSteam ? showSteam : showNonSteam) && - (!hideFull || s.Players < s.MaxPlayers) && - (search.Length == 0 || (s.Name ?? "").ToLower().Contains(search) || (s.Owner ?? "").ToLower().Contains(search))); + if (shownServers == null || Event.current.type == EventType.Layout) + shownServers = all.FindAll(s => + (s.RequireSteam ? showSteam : showNonSteam) && + (!hideFull || s.Players < s.MaxPlayers) && + (search.Length == 0 || (s.Name ?? "").ToLower().Contains(search) || (s.Owner ?? "").ToLower().Contains(search))); + List servers = shownServers; + string shownError = Event.current.type == EventType.Layout ? (layoutError = browser.Error) : layoutError; // Tabellenkopf Rect header = GUILayoutUtility.GetRect(10, 26, GUILayout.ExpandWidth(true)); @@ -200,7 +209,7 @@ namespace MSCO GUI.Label(new Rect(header.x + header.width * 0.76f, header.y, 50, header.height), "PING", headerCellStyle); serverScroll = GUILayout.BeginScrollView(serverScroll, GUILayout.Height(140)); - if (browser.Error != null) GUILayout.Label(browser.Error, textStyle); + if (shownError != null) GUILayout.Label(shownError, textStyle); if (servers.Count == 0) GUILayout.Label(browser.Loading ? "Loading servers..." : all.Count > 0 ? "No servers match your filters." : "No servers online right now.", textStyle); foreach (ServerListEntry s in servers)