bradcarman / ModelingToolkitDesigner.jl

A helper tool for visualizing and editing a ModelingToolkit.jl system connections
MIT License
95 stars 2 forks source link

Switch on the tutorial project #8

Closed ufechner7 closed 1 year ago

ufechner7 commented 1 year ago

When I run the tutorial project from the README there is a switch on the right hand of the buttons. When I click on it I get an exception:

julia> Error in callback:
type Nothing has no field color
Stacktrace:
  [1] getproperty(x::Nothing, f::Symbol)
    @ Base ./Base.jl:37
  [2] (::ModelingToolkitDesigner.var"#18#37"{ODESystemDesign, Figure})(event::Makie.MouseButtonEvent)
    @ ModelingToolkitDesigner ~/.julia/packages/ModelingToolkitDesigner/KiVKK/src/ModelingToolkitDesigner.jl:525
  [3] #invokelatest#2
    @ ./essentials.jl:816 [inlined]
  [4] invokelatest
    @ ./essentials.jl:813 [inlined]
  [5] notify
    @ ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:169 [inlined]
  [6] setindex!
    @ ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:86 [inlined]
  [7] (::GLMakie.var"#mousebuttons#153"{Observable{Makie.MouseButtonEvent}})(window::GLFW.Window, button::GLFW.MouseButton, action::GLFW.Action, mods::Int32)
    @ GLMakie ~/.julia/packages/GLMakie/9nid7/src/events.jl:102
  [8] _MouseButtonCallbackWrapper(window::GLFW.Window, button::GLFW.MouseButton, action::GLFW.Action, mods::Int32)
    @ GLFW ~/.julia/packages/GLFW/BWxfF/src/callback.jl:43
  [9] PollEvents
    @ ~/.julia/packages/GLFW/BWxfF/src/glfw3.jl:620 [inlined]
 [10] pollevents(screen::GLMakie.Screen{GLFW.Window})
    @ GLMakie ~/.julia/packages/GLMakie/9nid7/src/screen.jl:421
 [11] on_demand_renderloop(screen::GLMakie.Screen{GLFW.Window})
    @ GLMakie ~/.julia/packages/GLMakie/9nid7/src/screen.jl:876
 [12] renderloop(screen::GLMakie.Screen{GLFW.Window})
    @ GLMakie ~/.julia/packages/GLMakie/9nid7/src/screen.jl:902
 [13] (::GLMakie.var"#69#70"{GLMakie.Screen{GLFW.Window}})()
    @ GLMakie ./task.jl:514

What is the purpose of the switch?

bradcarman commented 1 year ago

The switch is used to hide the PassThru's. I'm not able to re-create this issue on my end. I've just updated this package to v1.0.0. Can you try updating your environment and try again?

albheim commented 1 year ago

I have the same error on v1.0.0

julia> Error in callback:
type Nothing has no field color
Stacktrace:
  [1] getproperty(x::Nothing, f::Symbol)
    @ Base ./Base.jl:37
  [2] (::ModelingToolkitDesigner.var"#24#44"{ODESystemDesign, Figure})(event::Makie.MouseButtonEvent)
    @ ModelingToolkitDesigner ~/.julia/packages/ModelingToolkitDesigner/W7BSJ/src/ModelingToolkitDesigner.jl:578
  [3] #invokelatest#2
    @ GLMakie ./essentials.jl:887 [inlined]
  [4] invokelatest
    @ GLMakie ./essentials.jl:884 [inlined]
  [5] notify
    @ GLMakie ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:169 [inlined]
  [6] setindex!
    @ GLMakie ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:86 [inlined]
  [7] (::GLMakie.var"#mousebuttons#153"{Observable{Makie.MouseButtonEvent}})(window::GLFW.Window, button::GLFW.MouseButton, action::GLFW.Action, mods::Int32)
    @ GLMakie ~/.julia/packages/GLMakie/toRaR/src/events.jl:102
  [8] _MouseButtonCallbackWrapper(window::GLFW.Window, button::GLFW.MouseButton, action::GLFW.Action, mods::Int32)
    @ GLFW ~/.julia/packages/GLFW/BWxfF/src/callback.jl:43
  [9] PollEvents
    @ GLMakie ~/.julia/packages/GLFW/BWxfF/src/glfw3.jl:620 [inlined]
 [10] pollevents(screen::GLMakie.Screen{GLFW.Window})
    @ GLMakie ~/.julia/packages/GLMakie/toRaR/src/screen.jl:421
 [11] on_demand_renderloop(screen::GLMakie.Screen{GLFW.Window})
    @ GLMakie ~/.julia/packages/GLMakie/toRaR/src/screen.jl:876
 [12] renderloop(screen::GLMakie.Screen{GLFW.Window})
    @ GLMakie ~/.julia/packages/GLMakie/toRaR/src/screen.jl:902
 [13] (::GLMakie.var"#69#70"{GLMakie.Screen{GLFW.Window}})()
    @ GLMakie ~/.julia/packages/GLMakie/toRaR/src/screen.jl:781

julia> versioninfo()
Julia Version 1.10.0-beta1
Commit 6616549950e (2023-07-25 17:43 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
  Threads: 1 on 8 virtual cores

(mtktest) pkg> st
Status `/tmp/mtktest/Project.toml`
  [e9467ef8] GLMakie v0.8.8
  [961ee093] ModelingToolkit v8.64.0
  [23d639d0] ModelingToolkitDesigner v1.0.0
  [16a59e39] ModelingToolkitStandardLibrary v2.1.1
ufechner7 commented 1 year ago

Same error on version 1.1. The error happens when I click on the dark blue circle of the switch, NOT when I toggle the switch. I am using Ubuntu 22.04.

(Designer) pkg> st
Status `~/repos/Designer/Project.toml`
  [13f3f980] CairoMakie v0.10.8
  [e9467ef8] GLMakie v0.8.8
  [961ee093] ModelingToolkit v8.64.0
  [23d639d0] ModelingToolkitDesigner v1.1.0
  [16a59e39] ModelingToolkitStandardLibrary v2.1.1
ufechner7 commented 1 year ago

From discourse: https://discourse.julialang.org/t/how-to-debug-type-nothing-has-no-field-color/103038/2

The stack trace of @albheim in that issue say that the problem is on line 578 in src/ModelingToolkitDesigner.jl on version v1.0.0: https://github.com/bradcarman/ModelingToolkitDesigner.jl/blob/f56140e8b4c46583f71ab8d694bff64376cddde5/src/ModelingToolkitDesigner.jl#L569-L579

Looks like there is a isnothing check missing:

if !isnothing(selected_component)
    selected_component.color[] = :pink
else
    all_connectors =
        vcat([s.connectors for s in design.components]...)
    selected_connector = filtersingle(
        c -> is_tuple_approx(c.xy[], (x, y); atol = 1e-3),
        all_connectors,
    )
    selected_connector.color[] = :pink # line nr. 578
end

So something like this might fix the problem:

    if ! isnothing(selected_connector)
        selected_connector.color[] = :pink 
    end