I'm trying to get adornments working in a mod, and it works most of the time, but I get a strange, sporadic, error.
I've cut this down to a very minimal test mod, and still get the error, with the mod essentially just the following code:
- Code: Select all
local LayoutHelpers = import('/lua/maui/layouthelpers.lua')
local Bitmap = import('/lua/maui/bitmap.lua').Bitmap
local overlays = {}
function CreateOverlay(unit)
local overlay = Bitmap(GetFrame(0))
overlay:SetTexture('/mods/SelectionHelper/textures/busy.dds', 0)
overlay.Width:Set(26)
overlay.Height:Set(26)
overlay:SetNeedsFrameUpdate(true)
overlay.OnFrame = function(self, delta)
if not (overlay.Width() == 26) then
LOG("overlay width is:", overlay.Width())
end
if unit:IsDead() then
local id = unit:GetEntityId()
overlays[id] = nil
overlay:Destroy()
else
local worldView = import('/lua/ui/game/worldview.lua').viewLeft
local pos = worldView:Project(unit:GetPosition())
LayoutHelpers.AtLeftTopIn(overlay, worldView, pos.x - overlay.Width() / 2, pos.y - overlay.Height() - 9)
end
end
return overlay
end
function ToggleFor(u)
local id = u:GetEntityId()
if overlays[id] == nil then
overlays[id] = CreateOverlay(u)
else
overlays[id]:Destroy()
overlays[id] = nil
end
end
function ToggleForSelection()
for _, u in GetSelectedUnits() or {} do
ToggleFor(u)
end
end
The full mod is attached, here:
Most of the time, when the mod works correctly, the adornment looks like this:
From time to time, however, something goes wrong, and the adornment gets created like this:
When it goes wrong, I get some errors in the log, as follows:
- Code: Select all
WARNING: Evaluating LazyVar failed: error evaluating lazy variable: ... alliance\gamedata\mohodata.scd\lua\maui\control.lua(37): error evaluating lazy variable: ... alliance\gamedata\mohodata.scd\lua\maui\control.lua(35): circular dependency in lazy evaluation for variable [Set lazyvar.ExtendedErrorMessages for extra trace info]
stack traceback:
[C]: in function `error'
...orged alliance\gamedata\mohodata.scd\lua\lazyvar.lua(21): in function `Bottom'
... alliance\gamedata\mohodata.scd\lua\maui\control.lua(35): in function <... alliance\gamedata\mohodata.scd\lua\maui\control.lua:35>
[C]: in function `pcall'
...orged alliance\gamedata\mohodata.scd\lua\lazyvar.lua(31): in function `Top'
... alliance\gamedata\mohodata.scd\lua\maui\control.lua(37): in function <... alliance\gamedata\mohodata.scd\lua\maui\control.lua:37>
[C]: in function `pcall'
...orged alliance\gamedata\mohodata.scd\lua\lazyvar.lua(31): in function <...orged alliance\gamedata\mohodata.scd\lua\lazyvar.lua:18>
Stack trace from definition: [Set lazyvar.ExtendedErrorMessages for extra trace info]
stack traceback:
[C]: in function `error'
...orged alliance\gamedata\mohodata.scd\lua\lazyvar.lua(37): in function `Top'
... alliance\gamedata\mohodata.scd\lua\maui\control.lua(37): in function <... alliance\gamedata\mohodata.scd\lua\maui\control.lua:37>
[C]: in function `pcall'
...orged alliance\gamedata\mohodata.scd\lua\lazyvar.lua(31): in function <...orged alliance\gamedata\mohodata.scd\lua\lazyvar.lua:18>
Stack trace from definition: [Set lazyvar.ExtendedErrorMessages for extra trace info]
stack traceback:
[C]: in function `error'
...orged alliance\gamedata\mohodata.scd\lua\lazyvar.lua(37): in function <...orged alliance\gamedata\mohodata.scd\lua\lazyvar.lua:18>
(And then the same again, by the looks of things, but referring to 'Right' and 'Left'.)
Has anyone seen this kind of error before, and have some idea what this could be about?
If you want to try repeating the issue, you should be able to just put the AdornmentTest.zip archive in your mods folder (no need to unzip, or turn on the mod in the UI), and then enter the following command in the in-game console a bunch of times (with something selected):
- Code: Select all
UI_Lua import("/mods/AdornmentTest/main.lua").ToggleForSelection()