Lyceum / LyceumMuJoCoViz.jl

MIT License
3 stars 0 forks source link

Weirdly stuck during access KeyEvent #30

Open sprhawk opened 3 years ago

sprhawk commented 3 years ago

I tried to load some complex model like this, below is code:

using LyceumBase, LyceumMuJoCo, LyceumMuJoCoViz

struct Husky{ S <: MJSim } <: AbstractMuJoCoEnvironment
    sim::S
end

LyceumMuJoCo.getsim(env::Husky) = env.sim

Husky() = first(tconstruct(Husky, 1))
function LyceumBase.tconstruct(::Type{Husky}, N::Integer)
    modelpath = joinpath(@__DIR__, "dual_ur5_husky/mobile_pick_and_place.xml")
    Tuple(Husky(s) for s in tconstruct(MJSim, N, modelpath, skip=1)) 
end

LyceumMuJoCo.getreward(state, action, obs, env::Husky) = 1.0
LyceumMuJoCo.geteval(state, action, obs, env::Husky) = 1.0

function husky_controller(env)
    setaction!(env, rand(actionspace(env)))
end
function husky_sim()
    env = Husky()
    visualize(env,
              controller = husky_controller
              )
    return env
end

Running like:

JULIA_NUM_THREADS=4 julia --project=.  -e 'include("husky.jl")' -e "husky_sim()" 

I'm using a Dell G15 (Intel i7-11800H with RTX 3060, Debian bullseye distribution)

When I run husky_sim(), most of time, after showing help message 'Press "F1" to show the help message.', then the visualize window will stuck, some time showed no scene some time showed right scene but still stuck, and I have to use many ctrl-c in julia to kill the process. and the julia process will use CPU 100% in one single thread.

I have no idea how it is happening


updated: I run husky_sim(), it will start / show Visualization UI, and fresh rate is being updated, but except using ESC to quit, any other Key Stroke will stuck the UI, and have to use Ctrl-C in julia REPL kill julia process. But after using ESC to quit, then re-run husky_sim, it will run normally.

Updated: the LyceumMuJoCoViz.jl has version: "0.2.5" And I tried to use pkg> dev ./LyceumMuJoCoViz.jl/ to use latest master (ee007ab071346658b2fa6f85cdd56827da961af2) also has same behavior ( stuck )

Updated: I added multiple printlns, and I find when stuck, it stuck at GLFW.PollEvents() here

Updated: I don't know whether I find is correct: I found it is blocked during send event, it stuck inside on(h, obs) ( in glfw.jl ), I tried

on(obs) do val
    ....
    println(val)
    h(val)
end

It seems whenever I access val, it is blocked.

Updated: When I access here https://github.com/Lyceum/LyceumMuJoCoViz.jl/blob/ee007ab071346658b2fa6f85cdd56827da961af2/src/glfw.jl#L340 if i println("event key: ", ev.key) or println("event action: ", ev.action), it will print the key value and action, and stuck during println("event: ", ev). But if I println("event time: ", ev.time), the program is not only blocked, even all other println I added for debug purpose will not be shown after shown "Press "F1" to show the help message. "