SirMallard / Iris

Iris is an Immediate-Mode GUI Library for Roblox for creating debug and visualisation UI and tools, based on Dear ImGui,
https://sirmallard.github.io/Iris/
MIT License
164 stars 25 forks source link

Too Many & Too Few End Calls #20

Closed madeinjei closed 1 year ago

madeinjei commented 1 year ago

Im trying to create this exact stack however I getting an error saying: Callback has too many calls to Iris.End() or To Few calls to Iris.End() I tried to follow the demo you have on the docs page and then diagnose by looking at your source but I dont know why this is an issue.

Iris.Init()

    Iris:Connect(function()
        Iris.Window({"MENU", [Iris.Args.Window.NoResize] = true}, {size = Vector2.new(100, 100)})

        if Iris.Button({"Spawn"}).clicked() then

            RemotesManager.Client:Get("SpawnPlayer"):SendToServer()
            Iris.End()
        end

        Iris.End()
    end)
JakeyWasTaken commented 1 year ago

Iris.Button doesnt require an end.

madeinjei commented 1 year ago

even so, I still end up with a too many end calls error

Michael-48 commented 1 year ago

In the case that the button is clicked, Iris.End() is called twice, instead:

    if Iris.Button({"Spawn"}).clicked() then
     -- call server
   end
   Iris.End()

Iris.End in branching code should only happen when a branch uses break, return, continue, etc. there is another problem, though, sendToServer yields. If the yield lasts longer than an Iris cycle, The same error will pop up.

    if Iris.Button({"Spawn"}).clicked() then
            task.spawn(function()
             -- call server
            end)
       end
       Iris.End()

I'm going to keep this issue opened because I think the behavior when attempting to yield should be improved, and should have an intuitive error.

Michael-48 commented 1 year ago

I'm going to keep this issue opened because I think the behavior when attempting to yield should be improved, and should have an intuitive error.

Ive made this change now: https://github.com/Michael-48/Iris/commit/e7bedd35d71196bae664f73375e6332040f6fb6e, closing the issue