From 57f6cb970bd8b85af552c92188255062e43f70b8 Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 14 Sep 2014 15:24:39 +0000 Subject: [PATCH] (svn r26820) [1.4] -Backport from trunk: - Fix: Crashes on joining a server with pending order backups [FS#6112] (r26819) - Fix: Crashes on start due to dereferencing the -1 index of the file names array of music files (r26809) --- src/music_gui.cpp | 17 +++++++++++------ src/saveload/afterload.cpp | 16 ++++++++++++++++ src/saveload/order_sl.cpp | 14 -------------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/music_gui.cpp b/src/music_gui.cpp index 1e20716512..bff064062a 100644 --- a/src/music_gui.cpp +++ b/src/music_gui.cpp @@ -200,12 +200,17 @@ static void SelectSongToPlay() memset(_cur_playlist, 0, sizeof(_cur_playlist)); do { - const char *filename = BaseMusic::GetUsedSet()->files[_playlists[_settings_client.music.playlist][i] - 1].filename; - /* We are now checking for the existence of that file prior - * to add it to the list of available songs */ - if (!StrEmpty(filename) && FioCheckFileExists(filename, BASESET_DIR)) { - _cur_playlist[j] = _playlists[_settings_client.music.playlist][i]; - j++; + /* File is the index into the file table of the music set. The play list uses 0 as 'no entry', + * so we need to subtract 1. In case of 'no entry' (file = -1), just skip adding it outright. */ + int file = _playlists[_settings_client.music.playlist][i] - 1; + if (file >= 0) { + const char *filename = BaseMusic::GetUsedSet()->files[file].filename; + /* We are now checking for the existence of that file prior + * to add it to the list of available songs */ + if (!StrEmpty(filename) && FioCheckFileExists(filename, BASESET_DIR)) { + _cur_playlist[j] = _playlists[_settings_client.music.playlist][i]; + j++; + } } } while (_playlists[_settings_client.music.playlist][++i] != 0 && j < lengthof(_cur_playlist) - 1); diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 0a97548f81..fd28758e37 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -51,6 +51,7 @@ #include "../core/backup_type.hpp" #include "../smallmap_gui.h" #include "../news_func.h" +#include "../order_backup.h" #include "../error.h" @@ -2914,6 +2915,21 @@ bool AfterLoadGame() } } + /* + * Only keep order-backups for network clients. + * If we are a network server or not networking, then we just loaded a previously + * saved-by-server savegame. There are no clients with a backup, so clear it. + * Furthermore before savegame version 192 the actual content was always corrupt. + */ + if (!_networking || _network_server || IsSavegameVersionBefore(192)) { + /* Note: We cannot use CleanPool since that skips part of the destructor + * and then leaks un-reachable Orders in the order pool. */ + OrderBackup *ob; + FOR_ALL_ORDER_BACKUPS(ob) { + delete ob; + } + } + /* Station acceptance is some kind of cache */ if (IsSavegameVersionBefore(127)) { diff --git a/src/saveload/order_sl.cpp b/src/saveload/order_sl.cpp index 59a6b29f86..46978e2891 100644 --- a/src/saveload/order_sl.cpp +++ b/src/saveload/order_sl.cpp @@ -288,20 +288,6 @@ void Load_BKOR() OrderBackup *ob = new (index) OrderBackup(); SlObject(ob, GetOrderBackupDescription()); } - - /* Only load order-backups for network clients. - * If we are a network server or not networking, then we just loaded a previously - * saved-by-server savegame. There are no clients with a backup, so clear it. - * Furthermore before savegame version 192 the actual content was always corrupt. - */ - if (!_networking || _network_server || IsSavegameVersionBefore(192)) { - /* Note: We cannot use CleanPool since that skips part of the destructor - * and then leaks un-reachable Orders in the order pool. */ - OrderBackup *ob; - FOR_ALL_ORDER_BACKUPS(ob) { - delete ob; - } - } } static void Ptrs_BKOR()