Skip to content

Commit

Permalink
Fix Lua errors when failing to set a music track on an empty playlist
Browse files Browse the repository at this point in the history
Closes #3194.

(cherry-picked from commit 5871557)
  • Loading branch information
irydacea committed Oct 7, 2018
1 parent 90cc456 commit e68bdd1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions data/lua/wml-tags.lua
Expand Up @@ -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
Expand Down

0 comments on commit e68bdd1

Please sign in to comment.