Crash on drawing arc long running app

Hi all, very new here and hoping to find a work around for this problem, or at least a cause.

I am drawing arcs for a timer, and found a great solution by mpilgrem in this forum post

The problem I discovered even with stripped back code, just mpilgrem’s arc drawer, then the app will crash out of the codea IDE after about 20mins.

I’m running this on a ipad mini retina, IOS version 8.0

Does anybody else experience this problem?
Any clue as to what is causing it and how it might be fixed?

@Famous - that’s very difficult to say without seeing the code and/or replicating the problem (and although we try to be very helpful here, I’m not sure if anyone will want to sit and wait for 20 minutes!).

I see there is a shader involved, which complicates things a bit.

I also note that the draw function creates a new temporary mesh at each draw, and these may only get discarded every minute or so when Codea does garbage collection. If the problem is that all the discarded meshes are piling up, I might try adding these lines under m:draw() in the arc function, which force immediate garbage collection.


It’s not elegant or efficient, but it may tell you where the problem lies.

Thanks Ignatz. The code is exactly what is in the forum where mpilgrem posts “Below is a Codea version 1.5 suggestion, making use of an example shader:”

I added in your garbage collection suggestion and I’m running now.

I have the trace from codea crash. It references an OpenGLES call which I’m googling

Other than trace from the crash reporter how else might I diagnose?
The reason I have gone with codea is because I’m a windows PC user with an Ipad, so I can’t bust out Xcode and debug.

Back in 20 mins :slight_smile:

Here’s an arc function which caches the mesh so avoids the problem of recreating the mesh every draw:

Thanks LoopSpace. I did see that code, but it looked very complex compared to the arc code I’m using.
1 hour of mesh draws and the app is still running pretty so I hope the GC has fixed my problem.
Thanks all.

.@Famous - try this code, which only has one permanent mesh. See comments in the code.

function setup()
    cx, cy = WIDTH / 2, HEIGHT / 2
    stroke(118, 223, 25)
    --NEW added callback function to update mesh if changed
    parameter.integer("width", 1, 100, 40,ChangeSettings)  
    parameter.integer("radius", 100, WIDTH / 2, 200,ChangeSettings)
    parameter.integer("startAngle", -180, 180, -130,ChangeSettings)
    parameter.integer("endAngle", -180, 180, 130,ChangeSettings)
    m = mesh()
    m.shader = shader("Patterns:Arc")
    m.shader.color = color(stroke())

function ChangeSettings()
    --as parameters will call this function when setting up, before the mesh is created
    --this code prevents an error
    if not m then return end 
    --the "1" in setRect is the rectangle's index (ie first rectangle in the mesh)
    m.shader.a1 = math.rad(startAngle)
    m.shader.a2 = math.rad(endAngle)
    m.shader.size = (1 - strokeWidth()/radius) * 0.5

function draw()
    --it should be sufficient to run ChangeSettings once at the end of setup
    --but this doesn't work for some reason. It seems to have to run a couple of times
    --before anything draws, which is odd
    --So this code makes it run a few times at the start. Strange.
    if ElapsedTime<0.20 then ChangeSettings() end