Anyone seen this strange 'Evaluating LazyVar failed' error?

Everything about mods can be found here.

Moderator: Morax

Anyone seen this strange 'Evaluating LazyVar failed' error?

Postby crispweed » 13 Nov 2017, 19:57

Hi there,

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:
AdornmentTest.zip
Minimal test mod, repeating the issue
(3.89 KiB) Downloaded 90 times


Most of the time, when the mod works correctly, the adornment looks like this:

adornment_good.JPG
what the adornment looks like when it works
adornment_good.JPG (196.88 KiB) Viewed 3926 times


From time to time, however, something goes wrong, and the adornment gets created like this:

adornment_bad.JPG
what the adornment looks like when it doesn't work
adornment_bad.JPG (181.88 KiB) Viewed 3926 times


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()
crispweed
Crusader
 
Posts: 33
Joined: 02 Jan 2017, 17:32
Has liked: 2 times
Been liked: 3 times
FAF User Name: crispweed

Re: Anyone seen this strange 'Evaluating LazyVar failed' err

Postby crispweed » 13 Nov 2017, 20:14

So I did the 'Set lazyvar.ExtendedErrorMessages for extra trace info' thing it tells you to do in the error message, and the fuller error info generated is then 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 from:
         stack traceback:
            ...orged alliance\gamedata\mohodata.scd\lua\lazyvar.lua(64): in function `SetFunction'
            ...orged alliance\gamedata\mohodata.scd\lua\lazyvar.lua(95): in function `Set'
            ... alliance\gamedata\mohodata.scd\lua\maui\control.lua(37): in function `ResetLayout'
            ...d alliance\gamedata\mohodata.scd\lua\maui\bitmap.lua(68): in function `ResetLayout'
            ... alliance\gamedata\mohodata.scd\lua\maui\control.lua(43): in function `OnInit'
            ...d alliance\gamedata\mohodata.scd\lua\maui\bitmap.lua(74): in function <...d alliance\gamedata\mohodata.scd\lua\maui\bitmap.lua:73>
            [C]: in function `InternalCreateBitmap'
            ...d alliance\gamedata\mohodata.scd\lua\maui\bitmap.lua(35): in function `initfn'
            ...data\faforever\gamedata\lua.nx2\lua\system\class.lua(258): in function <...data\faforever\gamedata\lua.nx2\lua\system\class.lua:246>
            ...ommander forged alliance\mods\adornmenttest\main.lua(9): in function `CreateOverlay'
            ...ommander forged alliance\mods\adornmenttest\main.lua(34): in function `ToggleFor'
            ...ommander forged alliance\mods\adornmenttest\main.lua(44): in function `ToggleForSelection'
            [string "import("/mods/AdornmentTest/main.lua").Togg..."](1): in main chunk
            [C]: in function `ConExecuteSave'
            ...alliance\gamedata\lua.scd\lua\ui\dialogs\console.lua(159): in function <...alliance\gamedata\lua.scd\lua\ui\dialogs\console.lua:158>
         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 from:
         stack traceback:
            ...orged alliance\gamedata\mohodata.scd\lua\lazyvar.lua(64): in function `SetFunction'
            ...orged alliance\gamedata\mohodata.scd\lua\lazyvar.lua(95): in function `Set'
            ... alliance\gamedata\mohodata.scd\lua\maui\control.lua(35): in function `ResetLayout'
            ...d alliance\gamedata\mohodata.scd\lua\maui\bitmap.lua(68): in function `ResetLayout'
            ... alliance\gamedata\mohodata.scd\lua\maui\control.lua(43): in function `OnInit'
            ...d alliance\gamedata\mohodata.scd\lua\maui\bitmap.lua(74): in function <...d alliance\gamedata\mohodata.scd\lua\maui\bitmap.lua:73>
            [C]: in function `InternalCreateBitmap'
            ...d alliance\gamedata\mohodata.scd\lua\maui\bitmap.lua(35): in function `initfn'
            ...data\faforever\gamedata\lua.nx2\lua\system\class.lua(258): in function <...data\faforever\gamedata\lua.nx2\lua\system\class.lua:246>
            ...ommander forged alliance\mods\adornmenttest\main.lua(9): in function `CreateOverlay'
            ...ommander forged alliance\mods\adornmenttest\main.lua(34): in function `ToggleFor'
            ...ommander forged alliance\mods\adornmenttest\main.lua(44): in function `ToggleForSelection'
            [string "import("/mods/AdornmentTest/main.lua").Togg..."](1): in main chunk
            [C]: in function `ConExecuteSave'
            ...alliance\gamedata\lua.scd\lua\ui\dialogs\console.lua(159): in function <...alliance\gamedata\lua.scd\lua\ui\dialogs\console.lua:158>
         
         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 from:
         stack traceback:
            ...orged alliance\gamedata\mohodata.scd\lua\lazyvar.lua(64): in function `SetFunction'
            ...orged alliance\gamedata\mohodata.scd\lua\lazyvar.lua(95): in function `Set'
            ... alliance\gamedata\mohodata.scd\lua\maui\control.lua(37): in function `ResetLayout'
            ...d alliance\gamedata\mohodata.scd\lua\maui\bitmap.lua(68): in function `ResetLayout'
            ... alliance\gamedata\mohodata.scd\lua\maui\control.lua(43): in function `OnInit'
            ...d alliance\gamedata\mohodata.scd\lua\maui\bitmap.lua(74): in function <...d alliance\gamedata\mohodata.scd\lua\maui\bitmap.lua:73>
            [C]: in function `InternalCreateBitmap'
            ...d alliance\gamedata\mohodata.scd\lua\maui\bitmap.lua(35): in function `initfn'
            ...data\faforever\gamedata\lua.nx2\lua\system\class.lua(258): in function <...data\faforever\gamedata\lua.nx2\lua\system\class.lua:246>
            ...ommander forged alliance\mods\adornmenttest\main.lua(9): in function `CreateOverlay'
            ...ommander forged alliance\mods\adornmenttest\main.lua(34): in function `ToggleFor'
            ...ommander forged alliance\mods\adornmenttest\main.lua(44): in function `ToggleForSelection'
            [string "import("/mods/AdornmentTest/main.lua").Togg..."](1): in main chunk
            [C]: in function `ConExecuteSave'
            ...alliance\gamedata\lua.scd\lua\ui\dialogs\console.lua(159): in function <...alliance\gamedata\lua.scd\lua\ui\dialogs\console.lua:158>
         
         stack traceback:
            [C]: in function `error'
            ...orged alliance\gamedata\mohodata.scd\lua\lazyvar.lua(37): in function <...orged alliance\gamedata\mohodata.scd\
crispweed
Crusader
 
Posts: 33
Joined: 02 Jan 2017, 17:32
Has liked: 2 times
Been liked: 3 times
FAF User Name: crispweed

Re: Anyone seen this strange 'Evaluating LazyVar failed' err

Postby Myxir » 13 Nov 2017, 20:14

didn't check your mod, but in my experience that error appears when you're creating UI elements (button, panel, ...) but don't assign them to a specific position, e.g. button missing information where to be put on a window

edit:
checked your code, the overlay element hasn't been assigned an initial position (even though you're setting it in the OnFrame function), mind giving that a try?
Unhappy with balance http://i.imgur.com/q5G2BlM.png
User avatar
Myxir
Evaluator
 
Posts: 791
Joined: 09 Apr 2012, 14:01
Has liked: 94 times
Been liked: 306 times
FAF User Name: Washy (irc)

Re: Anyone seen this strange 'Evaluating LazyVar failed' err

Postby crispweed » 13 Nov 2017, 20:30

So from that stack trace, it looks like the error occurs in the following line:

local overlay = Bitmap(GetFrame(0))

So I don't really understand the GetFrame(0) bit here, just copied this from somewhere else (idle engineers, I think).

Is there something wrong with this constructor call?
crispweed
Crusader
 
Posts: 33
Joined: 02 Jan 2017, 17:32
Has liked: 2 times
Been liked: 3 times
FAF User Name: crispweed

Re: Anyone seen this strange 'Evaluating LazyVar failed' err

Postby crispweed » 13 Nov 2017, 20:38

Myxir wrote:didn't check your mod, but in my experience that error appears when you're creating UI elements (button, panel, ...) but don't assign them to a specific position, e.g. button missing information where to be put on a window

edit:
checked your code, the overlay element hasn't been assigned an initial position (even though you're setting it in the OnFrame function), mind giving that a try?


Ok, yep, made that change, so far don't seem to be able to repeat the issue any more.
Thank you!
crispweed
Crusader
 
Posts: 33
Joined: 02 Jan 2017, 17:32
Has liked: 2 times
Been liked: 3 times
FAF User Name: crispweed

Re: Anyone seen this strange 'Evaluating LazyVar failed' err

Postby Myxir » 13 Nov 2017, 20:43

glad that it works!
GetFrame(0) gets you the "main" UI panel, where all the others (score, eco, chat, ...) are placed on
Unhappy with balance http://i.imgur.com/q5G2BlM.png
User avatar
Myxir
Evaluator
 
Posts: 791
Joined: 09 Apr 2012, 14:01
Has liked: 94 times
Been liked: 306 times
FAF User Name: Washy (irc)

Re: Anyone seen this strange 'Evaluating LazyVar failed' err

Postby nine2 » 15 Nov 2017, 10:15

Yeah so you can set some layout properties and let it infer others. Like if u set left and width it an infer right. However if u don't set two of them it can't infer it and it gets in a loop trying to use left to calculate right, which tries to infer it by using left.

Solution as previously mentioned is to set layout properties. Top left width etc

What are you up to?
nine2
Councillor - Promotion
 
Posts: 2416
Joined: 16 Apr 2013, 10:10
Has liked: 285 times
Been liked: 515 times
FAF User Name: Anihilnine

Re: Anyone seen this strange 'Evaluating LazyVar failed' err

Postby JJ173 » 15 Nov 2017, 13:31

For future reference - If anyone struggles with LazyVars, I made an entry on the wiki to help find out what's causing the issue. This entry teaches you how to enable extensive logging for lazy variables. It needs an edit to work with hooking, but it's a temporary solution thus far. Take a look: https://wiki.faforever.com/index.php?ti ... g_LazyVars
Check out the Nomads Campaign Project: viewtopic.php?f=2&t=15534
Check out my first Coop Mission: viewtopic.php?f=78&t=15605
User avatar
JJ173
Avatar-of-War
 
Posts: 148
Joined: 23 Oct 2015, 16:57
Location: Underground
Has liked: 19 times
Been liked: 50 times
FAF User Name: TheAdDad

Re: Anyone seen this strange 'Evaluating LazyVar failed' err

Postby crispweed » 19 Nov 2017, 17:34

JJ173 wrote:For future reference - If anyone struggles with LazyVars, I made an entry on the wiki to help find out what's causing the issue. This entry teaches you how to enable extensive logging for lazy variables. It needs an edit to work with hooking, but it's a temporary solution thus far. Take a look: https://wiki.faforever.com/index.php?ti ... g_LazyVars


For my issue, just adding the following line somewhere before the lazy vars error was triggered was enough to get the full stack trace info shown:

Code: Select all
import("/lua/lazyvar.lua").ExtendedErrorMessages = true
crispweed
Crusader
 
Posts: 33
Joined: 02 Jan 2017, 17:32
Has liked: 2 times
Been liked: 3 times
FAF User Name: crispweed

Re: Anyone seen this strange 'Evaluating LazyVar failed' err

Postby crispweed » 19 Nov 2017, 17:51

Anihilnine wrote:What are you up to?


I have a mod with some selection hotkey helpers, e.g. stuff like the 'AddNearestByCategoryToSelection' function in the mod I posted previously here:
viewtopic.php?f=41&t=13763

This has some stuff for selecting idle units of various types, but with the exact definition of 'idle' tweaked a bit to better capture the units I actually want to select.

Sometimes I want to give certain units the 'job' of just standing at a certain position, until I say otherwise.
An example of this might be a cloaked scout.
So I *don't* want this unit to then be included when I press a hotkey to select idle land units.

I added some functionality to enable such units to be flagged as 'busy', then, and I'm using the adornment to show visually which units have been flagged in this way.

This is probably something that is already supported by some other mods (e.g. UI-Party?), but I kind of like making my own version, so I can really understand what is going on, and tweak it to do exactly what I want.

It's kind of a work in progress, but if this sounds interesting for anyone, just shout, and I'll post an archive with the current state of this mod..
crispweed
Crusader
 
Posts: 33
Joined: 02 Jan 2017, 17:32
Has liked: 2 times
Been liked: 3 times
FAF User Name: crispweed

Next

Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest