From e68bdd1b5f479da2c1c0e1144cc4dbce1498bb44 Mon Sep 17 00:00:00 2001 From: Iris Morelle Date: Sat, 9 Jun 2018 18:53:18 -0400 Subject: [PATCH] Fix Lua errors when failing to set a music track on an empty playlist Closes #3194. (cherry-picked from commit 5871557dbfe407ab454d9f55be6bc2a0fcad0434) --- changelog.md | 3 +++ data/lua/wml-tags.lua | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 62ab350a5b5c..fd31dcd8eaee 100644 --- a/changelog.md +++ b/changelog.md @@ -245,6 +245,9 @@ be initially selected in the Unit Attack dialog. This bug also had the potential to cause units to the wrong attack when engaging or viewing damage calculations. + * Fixed Lua errors when setting a music track that cannot be found when the + playlist is already empty, e.g. if there's no music installed for the + game (issue #3194). ## Version 1.13.12 ### Security fixes diff --git a/data/lua/wml-tags.lua b/data/lua/wml-tags.lua index 159c76c9ae89..fe4a4139b879 100644 --- a/data/lua/wml-tags.lua +++ b/data/lua/wml-tags.lua @@ -277,17 +277,23 @@ function wml_actions.music(cfg) wesnoth.music_list.play(cfg.name) else if not cfg.append then - if cfg.immediate then + if cfg.immediate and wesnoth.music_list.current_i then wesnoth.music_list.current.once = true end wesnoth.music_list.clear() end + local m = #wesnoth.music_list wesnoth.music_list.add(cfg.name, not not cfg.immediate, cfg.ms_before or 0, cfg.ms_after or 0) local n = #wesnoth.music_list + if n == 0 then + return + end if cfg.shuffle == false then wesnoth.music_list[n].shuffle = false end - if cfg.title ~= nil then + -- Always overwrite shuffle even if the new track couldn't be added, + -- but title shouldn't be overwritten. + if cfg.title ~= nil and m ~= n then wesnoth.music_list[n].title = cfg.title end end