From e82d811ab09ba2b6933fa3d12c9872f56369db51 Mon Sep 17 00:00:00 2001 From: Iris Morelle Date: Sat, 19 May 2018 22:35:31 -0400 Subject: [PATCH] Fix [change_theme] crashing when theme= isn't specified Leaving theme= unspecified ought to have the same effect as providing it and setting it to an empty string. Without the check for a nil value, however, it would result in a crash like this: 20180519 22:31:54 error scripting/lua: lua/wml-tags.lua:922: bad argument #3 to '__newindex' (string expected, got nil) stack traceback: [C]: in metamethod '__newindex' lua/wml-tags.lua:922: in local 'cmd' lua/wml-utils.lua:145: in field 'handle_event_commands' lua/wml-flow.lua:6: in function --- changelog.md | 2 ++ data/lua/wml-tags.lua | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 07fe4957731e..59eee5efeb8d 100644 --- a/changelog.md +++ b/changelog.md @@ -163,6 +163,8 @@ (issue #3050). * Fixed a crash when using certain invalid color= values. * Fixed: unit halo remained after undoing a recall (issue #3065). + * [change_theme] no longer causes a Lua error when theme= is not specified + instead of explicitly set to an empty string. ## Version 1.13.12 ### Security fixes diff --git a/data/lua/wml-tags.lua b/data/lua/wml-tags.lua index a0ed3a55a74f..28866ea1cf23 100644 --- a/data/lua/wml-tags.lua +++ b/data/lua/wml-tags.lua @@ -920,7 +920,13 @@ function wml_actions.reset_fog(cfg) end function wesnoth.wml_actions.change_theme(cfg) - wesnoth.game_config.theme = cfg.theme + local new_theme = cfg.theme + + if new_theme == nil then + new_theme = "" + end + + wesnoth.game_config.theme = new_theme end function wesnoth.wml_actions.zoom(cfg)