apicici / cimgui-love

LÖVE module for Dear ImGui obtained by wrapping cimgui with LuaJIT FFI.
MIT License
76 stars 6 forks source link

"Invalid Draw Range" error when trying to use BeginPopupModal #3

Closed smallsco closed 2 years ago

smallsco commented 2 years ago

Hello,

I'm working on porting an app from your earlier love-imgui library to cimgui-love, as the old library stopped working under LÖVE 11.4. It's been a bit of a learning curve as I am not very familiar with C or the FFI, but for the most part things have been going smoothly.

The first roadblock I've run into has been getting popups to work. If I define a new popup using the BeginPopupModal function, and attempt to open it using the OpenPopup_Str function, I get the following "Invalid Draw Range" error:

Error: cimgui/love.lua:189: Invalid draw range.
stack traceback:
    [love "boot.lua"]:345: in function <[love "boot.lua"]:341>
    [C]: in function 'setDrawRange'
    cimgui/love.lua:189: in function 'RenderDrawLists'
    main.lua:27: in function 'draw'
    [love "callbacks.lua"]:168: in function <[love "callbacks.lua"]:144>
    [C]: in function 'xpcall'

Here is a love.draw() method that raises the above error:

love.draw = function()
    if imgui.Begin("testing") then
        if imgui.Button("Open Popup") then
            imgui.OpenPopup_Str("Popup")
        end
        if imgui.BeginPopupModal("Popup") then
            imgui.Text("This is in a popup")
            imgui.EndPopup()
        end
    end
    imgui.End()

    -- code to render imgui
    imgui.Render()
    imgui.RenderDrawLists()
end

I'm not sure if this is a bug with the library, or if it's just something that I'm doing wrong. Interestingly, if I use BeginPopup instead of BeginPopupModal it works correctly (although the popup is not a modal window, which is what I want).

I'm using an Intel Mac running MacOS 12.1 and Love 11.4, with the cimgui-love 1.86-1 release.

Thanks so much for your hard work on this library (and the last one)!

apicici commented 2 years ago

This seems to be a problem with version 1.86, as I tested your code with 1.85 and it works without problems. I believe the problem is with the rendering code on the lua side, I'll look into it and report back. In the meantime you can use the 1.85 release.

smallsco commented 2 years ago

Thanks, I just tested with the 1.85 release and can confirm that it is working.

apicici commented 2 years ago

It turns out this was bug in Dear ImGui 1.86. I updated to the 1.87 WIP release that has the necessary patches and should fix the problem.