最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

graphics - Assistance With Understanding Stack Over Flow Errors (Julia - GLMakie Package) - Stack Overflow

programmeradmin4浏览0评论

Below is my code:

using GLMakie

#Creation of constants
a = 2
b = 5
c = 7
d = 9

# Creaiton of observables
RadTheta2_2 = Observable(.523)
RadTheta3_12 = Observable(-1.288)
RadTheta4_12 = Observable(-2.567)

# Creation of desired points that change as observable changes
R1_x2 = d * cos(0) 
R1_y2 = d * sin(0)

R2_x2 = @lift a * cos.($RadTheta2_2)
R2_y2 = @lift a * sin.($RadTheta2_2)

R3_x_12 = @lift b * cos.($RadTheta3_12)
R3_y_12 = @lift b * sin.($RadTheta3_12)


R4_x_12 = @lift c * cos.($RadTheta4_12)
R4_y_12 = @lift c * sin.($RadTheta4_12)

# Creation of figure
fig = Figure(size = (3840,2160)) # we can always reduce, not upscale images

# Creation of the axes
ax = Axis(fig[1,1],
    titlealign = :center,
    titlefont= :bold,
    aspect = DataAspect(), # Makes the data fit the size of the graphic
    title = "Interactive Fourbar Mechanism",
    titlesize = 24,
    xlabel = "x direction",
    xlabelsize = 24,
    xminorticksvisible = true,
    xminridvisible = true,
    xminorticks = IntervalsBetween(5),
    ylabel = "y direction",
    ylabelsize = 24,
)

# These four lines are where the error is occurring
dLine = lines!(ax, [0,R1_x2], [0,R1_y2], color = "orange")
aLine = lines!(ax, [0,R2_x2], [0,R2_y2], color = "red")
bLine = lines!(ax, [R2_x2,R3_x_12], [R2_y2,R3_y_12], color = "blue")
cLine = lines!(ax, [R1_x2,R3_x_12], [R1_y2,R3_y_12], color = "black")

# Creation of legend
Legend(
    fig[1,2],
    [dLine, aLine, bLine, cLine],
    ["d [R1]", "a [R2]", "b [R3]","c [R4]"],
    height = 600,
   width = 200
)

sg = SliderGrid(
    fig[2, 1],
    (label = "θ2", range = -10:1:10, format = "rad", startvalue = 0),
#    (label = "ω2", range = -10000:0.01:10000, format = "{:.2f} Rad//sec", startvalue = 0),
#    (label = "α2", range = -10000:0.01:10000, format = "{:.2f} Rad//sec^2", startvalue = 0),
    width = 1200
)

sliderobservables = [s.value for s in sg.sliders]
connect!(RadTheta2_2, sliderobservables[1])

display(fig)

Please see attached jpg for error code. error picture

Desire Outcome: Basically I want the sliders (slider grid) to update the observable values. Upon updating the observable values, the positional vector will update. Finally, the graphic will refresh and display the new positional vectors.

What I Understand: I understand that it is a stack over flow error so it has something to do with a memory issue. As I understand the program is trying to repeat 39988 times (see line 8 from error jpg).

What I have tried I am using linux so I tried: ulimit -s 16384 (16 MB) so that I could increase the memory stack limit. Although the error persists.

What I am looking for: Can you assist me with better understanding my problem and the viable solutions that I could try.

Below is my code:

using GLMakie

#Creation of constants
a = 2
b = 5
c = 7
d = 9

# Creaiton of observables
RadTheta2_2 = Observable(.523)
RadTheta3_12 = Observable(-1.288)
RadTheta4_12 = Observable(-2.567)

# Creation of desired points that change as observable changes
R1_x2 = d * cos(0) 
R1_y2 = d * sin(0)

R2_x2 = @lift a * cos.($RadTheta2_2)
R2_y2 = @lift a * sin.($RadTheta2_2)

R3_x_12 = @lift b * cos.($RadTheta3_12)
R3_y_12 = @lift b * sin.($RadTheta3_12)


R4_x_12 = @lift c * cos.($RadTheta4_12)
R4_y_12 = @lift c * sin.($RadTheta4_12)

# Creation of figure
fig = Figure(size = (3840,2160)) # we can always reduce, not upscale images

# Creation of the axes
ax = Axis(fig[1,1],
    titlealign = :center,
    titlefont= :bold,
    aspect = DataAspect(), # Makes the data fit the size of the graphic
    title = "Interactive Fourbar Mechanism",
    titlesize = 24,
    xlabel = "x direction",
    xlabelsize = 24,
    xminorticksvisible = true,
    xminridvisible = true,
    xminorticks = IntervalsBetween(5),
    ylabel = "y direction",
    ylabelsize = 24,
)

# These four lines are where the error is occurring
dLine = lines!(ax, [0,R1_x2], [0,R1_y2], color = "orange")
aLine = lines!(ax, [0,R2_x2], [0,R2_y2], color = "red")
bLine = lines!(ax, [R2_x2,R3_x_12], [R2_y2,R3_y_12], color = "blue")
cLine = lines!(ax, [R1_x2,R3_x_12], [R1_y2,R3_y_12], color = "black")

# Creation of legend
Legend(
    fig[1,2],
    [dLine, aLine, bLine, cLine],
    ["d [R1]", "a [R2]", "b [R3]","c [R4]"],
    height = 600,
   width = 200
)

sg = SliderGrid(
    fig[2, 1],
    (label = "θ2", range = -10:1:10, format = "rad", startvalue = 0),
#    (label = "ω2", range = -10000:0.01:10000, format = "{:.2f} Rad//sec", startvalue = 0),
#    (label = "α2", range = -10000:0.01:10000, format = "{:.2f} Rad//sec^2", startvalue = 0),
    width = 1200
)

sliderobservables = [s.value for s in sg.sliders]
connect!(RadTheta2_2, sliderobservables[1])

display(fig)

Please see attached jpg for error code. error picture

Desire Outcome: Basically I want the sliders (slider grid) to update the observable values. Upon updating the observable values, the positional vector will update. Finally, the graphic will refresh and display the new positional vectors.

What I Understand: I understand that it is a stack over flow error so it has something to do with a memory issue. As I understand the program is trying to repeat 39988 times (see line 8 from error jpg).

What I have tried I am using linux so I tried: ulimit -s 16384 (16 MB) so that I could increase the memory stack limit. Although the error persists.

What I am looking for: Can you assist me with better understanding my problem and the viable solutions that I could try.

Share Improve this question asked Mar 24 at 13:19 VolarusVolarus 1
Add a comment  | 

1 Answer 1

Reset to default 0

I am able to reproduce this error. Although I am unsure of its roots, I have run into this in the past. There is clearly a memory leak being set up by either @lift..., or by the accessing of lifted observables, like lines!(...[R2_x2,R3_x_12]...). In this case, my guess is that the latter is continuously creating that vector and storing it in stack memory. The solution I recommend is to simply avoid observable dependencies, by creating unique observables for each of their use cases. I could be argued that this is also easier to maintain, as there are explicit observables for each parameter, although it is more verbose.


To use this method, we need to:

  1. Set up the problem (unchanged)
  2. Create observables for each unique value we want accessed
  3. Spawn a slider, and have it interact with every observable
  4. Add lines to plot (unchanged)

We will set up the problem with the same ideas as before. Since the const keyword will result in slight performance benefits, I included that as well.


using GLMakie

# constants
const a = 2
const b = 5
const c = 7
const d = 9

Now, instead of just defining observables for your base angles, we define observables for everything that uses them too.


# create observables for angles
RadTheta2_2 = Observable(.523)
RadTheta3_12 = Observable(-1.288)
RadTheta4_12 = Observable(-2.567)

# create observables for calculated node coordinates
R1_x2 = d * cos(0) 
R1_y2 = d * sin(0)
R2_x2 = Observable(a * cos.(RadTheta2_2[]))
R2_y2 = Observable(a * sin.(RadTheta2_2[]))
R3_x_12 = Observable(b * cos.(RadTheta3_12[]))
R3_y_12 = Observable(b * sin.(RadTheta3_12[]))
R4_x_12 = Observable(c * cos.(RadTheta4_12[]))
R4_y_12 = Observable(c * sin.(RadTheta4_12[]))

# create observables for created line segments
seg1x = Observable([0,R1_x2[]])
seg1y = Observable([0,R1_y2[]])
seg2x = Observable([0,R2_x2[]])
seg2y = Observable([0,R2_y2[]])
seg3x = Observable([R2_x2[],R3_x_12[]])
seg3y = Observable([R2_y2[],R3_y_12[]])
seg4x = Observable([R1_x2[],R3_x_12[]])
seg4y = Observable([R1_y2[],R3_y_12[]])

Now, we need to assign logic to our slider to make it alter the observables.


# create figure
fig = Figure(size = (3840/4,2160/4)) # we can always reduce, not upscale images

# create slider
sg = SliderGrid(fig[2, 1],(label = "θ2", range = -10:.1:10, format = "rad", startvalue = 0))

# assign slider logic
on(sg.sliders[1].value) do val
    RadTheta2_2[]   = val
    R2_x2[]         = a * cos.(val)
    R2_y2[]         = a * sin.(val)
    R3_x_12[]       = b * cos.(RadTheta3_12[])
    R3_y_12[]       = b * sin.(RadTheta3_12[])
    R4_x_12[]       = c * cos.(RadTheta4_12[])
    R4_y_12[]       = c * sin.(RadTheta4_12[])
    
    seg1x[] = [0,R1_x2[]]
    seg1y[] = [0,R1_y2[]]
    seg2x[] = [0,R2_x2[]]
    seg2y[] = [0,R2_y2[]]
    seg3x[] = [R2_x2[],R3_x_12[]]
    seg3y[] = [R2_y2[],R3_y_12[]]
    seg4x[] = [R1_x2[],R3_x_12[]]
    seg4y[] = [R1_y2[],R3_y_12[]]
end

Now, we just need to plot the lines and legend. This is the same as your provided code.



# create ax
ax = Axis(fig[1,1],
    titlealign = :center,
    titlefont= :bold,
    aspect = DataAspect(), # Makes the data fit the size of the graphic
    title = "Interactive Fourbar Mechanism",
    xlabel = "x direction",
    xminorticksvisible = true,
    xminridvisible = true,
    xminorticks = IntervalsBetween(5),
    ylabel = "y direction"
)

aLine = lines!(ax, seg1x, seg1y, color = "orange")
bLine = lines!(ax, seg2x, seg2y, color = "red")
cLine = lines!(ax, seg3x, seg3y, color = "blue")
dLine = lines!(ax, seg4x, seg4y, color = "black")

# Creation of legend
Legend(
    fig[1,2],
    [dLine, aLine, bLine, cLine],
    ["d [R1]", "a [R2]", "b [R3]","c [R4]"]
)

display(fig)

This avoids any memory leaks, by circumventing any observable dependencies. This fixes your memory problem, but I believe, after seeing the plot, that there may be a bug in how segments 1 and 4 are being placed.

发布评论

评论列表(0)

  1. 暂无评论