flamendless / Slab

An immediate mode GUI for the Love2D framework.
MIT License
289 stars 25 forks source link

[Bug] Crash with `BeginContextMenuWindow` for void space #96

Closed Avril112113 closed 3 years ago

Avril112113 commented 3 years ago

In the wiki, the "Context Menus" example states that "This is placed outside of a BeginWindow/EndWindow call for context menus in the void space.", which no longer works since v0.8.0.

Minimal breaking example:

local Slab = require "Slab.API"

function love.update(dt)
    Slab.Update(dt)

    if Slab.BeginContextMenuWindow() then
        Slab.EndContextMenu()
    end
end

Traceback:

Error: libs/Slab//Internal/UI/Window.lua:143: attempt to perform arithmetic on field 'TitleH' (a nil value)
stack traceback:
        [string "boot.lua"]:777: in function '__sub'
        libs/Slab//Internal/UI/Window.lua:143: in function 'IsMouseHovered'
        libs/Slab//Internal/UI/Menu.lua:310: in function 'BeginContextMenuWindow'
        main.lua:36: in function 'update'
        [string "boot.lua"]:612: in function <[string "boot.lua"]:594>
        [C]: in function 'xpcall'
flamendless commented 3 years ago

Indeed. Idk if i should just edit the wiki and remove that claim haha just kidding. Fix is coming soon

flamendless commented 3 years ago

@Dude112113 this bug has been patched in the latest commit. Do note that you need items between the BeginContextMenuWindow and EndContextMenuWindow call to actually see it. No items will technically not show any context menu because there is nothing to render, therefore no height, therefore no window.