Changeset - r25918:16e244d420c6
[Not reviewed]
master
0 1 0
Patric Stout - 3 years ago 2021-08-21 09:56:29
truebrain@openttd.org
Fix: [Network] crash when last-joined server that is no longer available (#9503)

If you update the server-list while not having last-joined selected
and it is no longer available, the game crashed.
1 file changed with 7 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/network/network_gui.cpp
Show inline comments
 
@@ -249,15 +249,21 @@ protected:
 
		this->servers.clear();
 

	
 
		bool found_current_server = false;
 
		bool found_last_joined = false;
 
		for (NetworkGameList *ngl = _network_game_list; ngl != nullptr; ngl = ngl->next) {
 
			this->servers.push_back(ngl);
 
			if (ngl == this->server) {
 
				found_current_server = true;
 
			}
 
			if (ngl == this->last_joined) {
 
				found_last_joined = true;
 
			}
 
		}
 
		/* A refresh can cause the current server to be delete; so unselect. */
 
		if (!found_last_joined) {
 
			this->last_joined = nullptr;
 
		}
 
		if (!found_current_server) {
 
			if (this->server == this->last_joined) this->last_joined = nullptr;
 
			this->server = nullptr;
 
			this->list_pos = SLP_INVALID;
 
		}
0 comments (0 inline, 0 general)