Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Crash on drawing arc long running app

edited August 2014 in Questions Posts: 20

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 http://codea.io/talk/discussion/1156/drawing-an-arc/p1

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?

Tagged:

Comments

  • IgnatzIgnatz Mod
    Posts: 5,396

    @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.

    m=nil
    collectgarbage()
    

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

  • Posts: 20

    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 :-)

  • Posts: 509

    Here's an arc function which caches the mesh so avoids the problem of recreating the mesh every draw: http://codea.io/talk/discussion/comment/45163#Comment_45163

  • Posts: 20

    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.

  • IgnatzIgnatz Mod
    Posts: 5,396

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

    supportedOrientations(LANDSCAPE_ANY)
    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:addRect(cx,cy,radius,radius)
        m.shader.color = color(stroke())
    end
    
    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:setRect(1,cx,cy,radius*2,radius*2) 
        m.shader.a1 = math.rad(startAngle)
        m.shader.a2 = math.rad(endAngle)
        m.shader.size = (1 - strokeWidth()/radius) * 0.5
    end
    
    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
        background(64)
        strokeWidth(width)
        m:draw()
    end
    
    
Sign In or Register to comment.