Giter Club home page Giter Club logo

Comments (6)

FaresX avatar FaresX commented on July 24, 2024 1

Just a little while ago, I found that the problem is the using of deepcopy instead of remote_do.

from cimgui.jl.

Gnimuc avatar Gnimuc commented on July 24, 2024

You could use PushID() / PopID().

from cimgui.jl.

FaresX avatar FaresX commented on July 24, 2024
function edit(insbuf::InstrBuffer, addr)
    for qt in insbuf.quantities
        CImGui.PushID(qt.name)
        edit(qt, insbuf.instrnm, addr)
        CImGui.PopID()
    end
end
isvalidaddr = selectaddr in append!(collect.(keys.(values(instrbuffer)))...)
selectaddr = isvalidaddr ? selectaddr : ""
selectins in keys(default_insbufs) || push!(default_insbufs, selectins=>InstrBuffer(selectins))
insbuf = selectaddr == "" ? default_insbufs[selectins] : instrbuffer[selectins][selectaddr]
CImGui.PushID(string(selectins, selectaddr))
edit(insbuf, selectaddr)
CImGui.PopID()

image
I have tried it. There exists the same problem and I think it is not because of the IDs. When I do not select any addresses, there is no problem. Here, "instrbuffer" is a global variable in my module, and "default_insbufs" is a local variable inside a let block.

from cimgui.jl.

Gnimuc avatar Gnimuc commented on July 24, 2024

Please submit an MWE, I'm not responsible for debugging your incomplete code with such limited info.

from cimgui.jl.

FaresX avatar FaresX commented on July 24, 2024

I have fixed this issue, but I am not clear about the reason. According to your suggestion, I wrote the sample code below. When I follow the workflow that generates data remotely and fetches back, the problem will be reproduced. However, when all things happen locally, there will be no problem.

module Example

using CImGui
using CImGui.CSyntax
using CImGui.CSyntax.CStatic
using CImGui.GLFWBackend
using CImGui.OpenGLBackend
using CImGui.GLFWBackend.GLFW
using CImGui.OpenGLBackend.ModernGL
using CImGui.LibCImGui
using Distributed

function ui()
    glsl_version = 130
    GLFW.WindowHint(GLFW.CONTEXT_VERSION_MAJOR, 3)
    GLFW.WindowHint(GLFW.CONTEXT_VERSION_MINOR, 0)
    error_callback(err::GLFW.GLFWError) = @error "GLFW ERROR: code $(err.code) msg: $(err.description)"

    # setup GLFW error callback
    GLFW.SetErrorCallback(error_callback)
    # create window
    window = GLFW.CreateWindow(1920, 1080, "Example")
    @assert window != C_NULL
    GLFW.MakeContextCurrent(window)
    GLFW.SwapInterval(1)  # enable vsync

    # setup Dear ImGui context
    ctx = CImGui.CreateContext()
    # setup Dear ImGui style
    CImGui.StyleColorsDark()

    # setup Platform/Renderer bindings
    ImGui_ImplGlfw_InitForOpenGL(window, true)
    ImGui_ImplOpenGL3_Init(glsl_version)

    @async try
        p_open = true
        while !GLFW.WindowShouldClose(window)
            GLFW.PollEvents()
            ImGui_ImplOpenGL3_NewFrame()
            ImGui_ImplGlfw_NewFrame()
            CImGui.NewFrame()

            p_open && @c showexample(&p_open)

            CImGui.Render()
            GLFW.MakeContextCurrent(window)
            display_w, display_h = GLFW.GetFramebufferSize(window)
            glViewport(0, 0, display_w, display_h)
            glClearColor(0.2, 0.2, 0.2, 1) 
            glClear(GL_COLOR_BUFFER_BIT)
            ImGui_ImplOpenGL3_RenderDrawData(CImGui.GetDrawData())

            GLFW.MakeContextCurrent(window)
            GLFW.SwapBuffers(window)
            yield()
        end
    catch e
        @error "Error in renderloop!" exception=e
        Base.show_backtrace(stderr, catch_backtrace())
    finally
        ImGui_ImplOpenGL3_Shutdown()
        ImGui_ImplGlfw_Shutdown()
        CImGui.DestroyContext(ctx)
        GLFW.DestroyWindow(window)
    end
end

function showexample(p_open::Ref)
    CImGui.SetNextWindowPos((600, 100), CImGui.ImGuiCond_Once)
    CImGui.SetNextWindowSize((1000, 800), CImGui.ImGuiCond_Once)
    if CImGui.Begin("Example", p_open)
        CImGui.Button("Add Test") && (add_remote(); add_local())
        # CImGui.Button("Add Test") && push!(testlist, Test())
        for (i, test) in enumerate(testlist)
            CImGui.PushID(i)
            edit(test)
            CImGui.PopID()
        end
        CImGui.End()
    end
end

mutable struct Test
    input1
    input2
end

Test() = Test("\0"^16, "\0"^16)

function edit(t::Test)
    CImGui.InputTextWithHint("Input1", "Input1", t.input1, length(t.input1)); CImGui.SameLine()
    CImGui.InputTextWithHint("Input2", "Input2", t.input2, length(t.input2))
end

testlist = []

function add_remote()
    remotecall_wait(workers()[1]) do 
        push!(testlist, Test())     
    end
end

function add_local()
    testlist_remote = remotecall_fetch(()->testlist, workers()[1]) |> deepcopy
    global testlist = testlist_remote
end

end # Example

Example.ui()

from cimgui.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.