keharriso / love-nuklear

Lightweight immediate mode GUI for LÖVE games
MIT License
350 stars 32 forks source link

Error when pushing style: 'attempt to index a nil value' #35

Closed megagrump closed 5 years ago

megagrump commented 5 years ago

Code to reproduce the issue:

local ui = nk.newUI()

ui:stylePush({
    checkbox = {
        normal = love.graphics.newImage('checkbox.png'),
    },
})

Stack trace:

Error: attempt to index a nil value
stack traceback:
    [string "boot.lua"]:637: in function <[string "boot.lua"]:633>
    [C]: in function 'stylePush'
    main.lua:4: in main chunk
    [C]: in function 'require'
    [string "boot.lua"]:475: in function <[string "boot.lua"]:311>
    [C]: in function 'xpcall'
    [string "boot.lua"]:645: in function <[string "boot.lua"]:639>
    [C]: in function 'xpcall'

The error gets thrown when calling pushStyle() before calling frameBegin(). I have an app that pushes a style when it starts, before the first frameBegin() - this worked fine with an older version of love-nuklear.

Is this by design? Are static styles to be pushed in every frame?

megagrump commented 5 years ago

A workaround:

function love.load()
    ui:frameBegin()
    ui:stylePush(style)
    ui:frameEnd()
end

It's not pretty, but the style sticks between frames.

keharriso commented 5 years ago

v2.5 should solve this problem. Let me know if the issue persists.

megagrump commented 5 years ago

Works fine now, thanks