Grid causes crash

Attached is my World Grid which is adapted from the grid used in the voxel editor project by @John.

It’s pretty elegant code I think, small and straightforward.

I put in a parameter control that changes the render distance of the grid—it’s the second one.

If I turn it on and off three times or so, Codea crashes.

Can anyone see what’s happening there (again, most of it is pretty small and straightforward code, mainly because it’s not mine :slight_smile: )?

basically every time you turn this off and on, the craft scene engine has to regenerate the mipmaps-

if not self.shortenedRenderDistance then
        craft.texture(self.img):generateMipmaps()   --remove fog effect
        self.img.premultipled=true
    end

this means all these mipmaps steal memory and are never cleaned up, i’m not sure if there is a direct way to destroy them but if you add the line collectgarbage() at the end of the draw function it will fix the crash

personally i use collectgarbage() at the end of my draw function in all projects i’ve worked on as i don’t see it effecting performance at all and it’s only beneficial to have cleanup every frame

@skar @UberGoober - tried adding the collectgarbage() in the draw function then flipped the visible/invisible parameter several times then the second parameter Codea crashed.

I don’t think it’s something to do with the setting up parameters part of the class. I think they may need to be independent of the class and call the class with the entity id.

hmm it works to fix the crashing for me, maybe because i’m on the M1 chip

For me, it crashes every time I slide the parameter “grid fades with distance”.

collectgarbage() is working for me so far.

If I put collectgarbage() in draw, it still crashes every time I slide the “grid fades with distance” to off.

@dave1707 please let me know if you ever find a solution.

I’d try to help if I could, but I can’t see what I could really do, because it’s not happening for me anymore. If there’s a way I can help I’ll be happy to.

All, can you post what your iOS and kit id’s are. I get exactly the same as @dave1707. Although I have played around with it a bit, but I don’t think the changes I made are responsible.

@skar - in there fast, how you finding the M1?

@Bri_G it’s awesome, i got the 11” and it flys through everything