A useless stack traceback

Discussion of Lua and LuaWML support, development, and ideas.

Moderators: Forum Moderators, Developers

Post Reply
Inactive Developer
Posts: 2460
Joined: August 15th, 2008, 8:46 pm
Location: Germany

A useless stack traceback

Post by Anonymissimus » November 8th, 2010, 7:31 pm

At least in this case the backtrace was helpful, the problem was that the SLF looking for a suitable nearest hex was quite restrictive, thus nNearestHex was nil...

Since 1.9 it happens very few times that I get a backtrace that doesn't make any sense, here is one.
The "attempt to index field '?' (a nil value)" is in common I think.

Code: Select all

20101108 20:13:47 error scripting/lua: ...ata/data/add-ons/The_Earths_Gut/lua/teg_wml_tags.lua:127: attempt to index field '?' (a nil value)
stack traceback:
	...ata/data/add-ons/The_Earths_Gut/lua/teg_wml_tags.lua:127: in function 'cmd'
	E:/Programme/WesnothTrunk/data/lua/wml-tags.lua:220: in function 'handle_event_commands'
	E:/Programme/WesnothTrunk/data/lua/wml-tags.lua:234: in function 'if_while_handler'
	E:/Programme/WesnothTrunk/data/lua/wml-tags.lua:244: in function 'cmd'
	E:/Programme/WesnothTrunk/data/lua/wml-tags.lua:220: in function 'handle_event_commands'
	E:/Programme/WesnothTrunk/data/lua/wml-tags.lua:234: in function 'if_while_handler'
	E:/Programme/WesnothTrunk/data/lua/wml-tags.lua:240: in function 'cmd'
	E:/Programme/WesnothTrunk/data/lua/wml-tags.lua:220: in function <E:/Programme/WesnothTrunk/data/lua/wml-tags.lua:213>
note that line 127 in teg_wml_tags.lua is this line
nX, nY = tPossibleNearestHexes[nNearestHex][1], tPossibleNearestHexes[nNearestHex][2]

Code: Select all

function wml_actions.nearest_hex(cfg)
	local error_msg = "error in [nearest_hex] while reading the source location"
 	local nX = tonumber(cfg.x_source) or helper.wml_error(error_msg)
	local nY = tonumber(cfg.y_source) or helper.wml_error(error_msg)
	local sVariable = cfg.variable

	local slf = helper.shallow_literal(cfg); slf.x_source = nil; slf.y_source = nil; slf.variable = nil -- slf: StandardLocationFilter
	local tPossibleNearestHexes = wesnoth.get_locations(slf)

	local nNearestHex = nil
	local nNearestHexDistance = MAX_NUMBER
	local nPossibleNearestHexDistance = MAX_NUMBER
	for nCurrentHex, tCurrentHex in ipairs(tPossibleNearestHexes) do
		nPossibleNearestHexDistance = helper.distance_between(nX, nY, tCurrentHex[1], tCurrentHex[2])

		if(nPossibleNearestHexDistance < nNearestHexDistance) then
			nNearestHexDistance = nPossibleNearestHexDistance
			nNearestHex = nCurrentHex

	nX, nY = tPossibleNearestHexes[nNearestHex][1], tPossibleNearestHexes[nNearestHex][2]
	if sVariable then
		wesnoth.set_variable(sVariable, { x = nX, y = nY, terrain = wesnoth.get_terrain(nX, nY) })
	return tPossibleNearestHexes[nNearestHex]
which is tested and used to work. It is however recently changed which seems to be in common for the useless backtraces too.
The wml code calling this tag has already been executed successfully several times in this scenario until the error occurred. Also, as far as I noticed, the lua code did work despite the error. I may investigate further...
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign

Post Reply