Howdy, Stranger!

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

performance issues when dealing with many meshes filled with colours

edited March 2014 in Questions Posts: 277

Hi there,

It's been a while since I managed to play with Codea...
I've been trying to learn more about meshes lately. for this, I take the Physics labs exemple as a start, more precisely, test 1, where I try to change the code to fill each polygon with a different colour.

What I did is this:

in the function function createRandPoly() (in main), I add, at line 95:
poly.col = color(math.random(0,255), math.random(0,255), math.random(0,255),255)

in the function draw(), at line 87 of PhysicsDebugDraw, instead of drawing each polygon as an outline with a simple line, I do
meshName = mesh()
meshName.vertices = triangulate(points)

This indeed draw polygons as a colour-filled shape instead of as an outline. My problem is that by tapping around and adding 50 or 60 polygons, the program quickly gets really slow and eventually shuts down (while everything is really smooth when only drawing the outline as the demo shows).

To a novice, it looks like a really bad memory leak. Is it because I do meshName:draw() within the draw function? What's the proper way to fill a polygon in such situation?




  • Posts: 2,161

    It looks from your description as though you are creating the meshes afresh every draw cycle. This is not the usual way to handle meshes. Create them once and then jst draw them each cycle.

  • JohnJohn Admin Mod
    Posts: 564

    Hi @Rodolphe. The reason your project is slowing down is that you are creating meshes every time draw is called. The triangulate function is also somewhat slow. If you only create the meshes once when your physics object is created and re-use it you should see improvements in performance.

  • Posts: 277

    oh, ok! I'll try this now...

  • IgnatzIgnatz Mod
    Posts: 5,396

    @Rodolphe - it's always difficult to be sure without seeing the code, but the problem is probably that you are creating new meshes for all your objects, 60 times per second. Normally, you would create them once, and then just draw them after that.

    Additionally, the debugdraw code does a lot more than you need for your simple example. In my view, it is a misleading demo, because you can use far less code to do the same thing.

    I would suggest making your own example instead.

  • edited March 2014 Posts: 239

    The issue is in function draw. I think your program is drawing a mesh each time you touch the screen. EDIT @Andrew_Stacey @John @Ignatz all I did was have a quick round of beelicious and you guys already commented. That was quick @-)

  • edited March 2014 Posts: 277

    Alright, I made it work (I think) as you suggested: by inserting meshes into a table as they are created, and then drawing each of them in draw()!

    Thanks a lot!

Sign In or Register to comment.