Codea crash when using mesh

Hi AIl,

This is mainly aimed toward @Simeon. I’m using Codea 3.4.3 (301) on an iPad Air 4. The project provided should
hopefully run as-is without modification but when increasing the value at RoundedRect.lua:196 above 10 Codea
crashes suddenly, often with no crash dialog.

The buffer isn’t even very large as far as vertex buffers go which makes it all the more confusing.

It appears to be crashing when creating the buffer rather than at render time as removing the mesh:draw() call does not
solve this.

Any light shed on this would be much appreciated.

Thanks in advance!

@Steppers - crashes on mine, it’s obviously when the number of increments required for the transition exceeds 10. The value of the increment of I/segs when 10 is used is always a multiple of 0.1 up to the limit of 1.0. Just don’t know why.

@Bri_G Yep, that’s exactly what I’ve been seeing but have no idea why.

The code is doing what it should though, it’s just generating the vertices for the rounded corners. It had originally been local segs = math.max(8, r // 4) so it would scale with the radius of the border to maintain detail. I thought it was that initially until I removed it and saw the same thing :confused:

@Steppers Here’s something interesting. In RoundRect, function corner, comment out the 3 add_vert calls. Change to segs=11. Run the code, then stop it. Uncomment add_vert(last), run the code, then stop it. Uncomment add_vert(current), run the code, then stop it. Uncomment add_vert(root), run the code. It will run, but might not look right. Stop the code and run it again. Sometimes it will run and look OK, sometimes it won’t, but it still runs. Not sure what’s happening, haven’t looked at the add_vert function yet.

             local segs = 11
            local function corner(id, root, last)
                for i = 1, segs do
                    local rad = math.rad((id + (i / segs)) * 90)
                    local current = root + vec3(math.sin(rad) * r, math.cos(rad) * r, 1)
                    last = current

@dave1707 That’s exactly what I’ve been seeing too. Sometimes one of the central triangles was completely missing?

I think I’ll need some input from someone who can connect a debugger to Codea to see what’s going on at this point.

@Steppers Is there a way you can move the function add_vert out of the function it’s in so it’s a function by it self. I’m not sure how well functions inside of functions work, I never do that so I don’t know if that matters.

@dave1707 I could but it wouldn’t make any difference as functions are first-class values in Lua. local functions just mean I can have helper functions inside of others when I don’t need them elsewhere.

It looks like all add_vert does is add info to tables. But then the 2 tables are local, so not sure about that either.

Ok, all working now… I think it’s down to the buffer:set(table) function.

I’ve replaced it all with this now and it works just fine:

local segs = 32
local vert_count = (6*5) + (segs * 3 * 4)
local vert = self.mesh:buffer("vert")
local vert_i = 1
local add_vert = function(v)
    vert[vert_i] = v
    vert_i = vert_i + 1

if has_tex then

    local uv = self.mesh:buffer("uv")
    add_vert = function(v)
        vert[vert_i] = v
        uv[vert_i] = vec2(v.x / w, v.y / h)
        vert_i = vert_i + 1

@Simeon It may be worth taking a look at that function :confused: