Codea Crashes to desktop when using physics.body.destroy()

I know this is my fault. I just want to destroy the physics bodies when they reach a value, say x < -100. In the example I provide below, destruction is set for x < 200. Unfortunately when that occurs, I get booted to desktop.

I offer double the usual amount of free points, so 2 million free points to the kind soul that figures out how to destroy the physics bodies without crashing Codea.

The problem is on line 111.

-- displayMode(FULLSCREEN)
    
function setup()
    --cliff variables
    cliffWidth = WIDTH/8
    scrollSpeed = -5
      
    decayrate = .5
    scrollSpeed = -5
    timeBetweenCliffs = 90
    cliffTimer = 80
    nextCliff = 1
    
    
    -- Physics variables
    physics.gravity(0,0)
    
    -- testCliff = CliffGroup()
    
    
    touches = {}
    

end

function draw()
    background(0, 178, 255, 255)
    
    -- Timers and loops
    cliffTimer = cliffTimer + 1
    
    if cliff1~= nil then
        cliff1:draw()
    end
    
    if cliff2~= nil then
        cliff2:draw()
    end
    
    if cliff3~= nil then
        cliff3:draw()
    end
    
    if cliffTimer == timeBetweenCliffs then
        if nextCliff == 1 then
            cliff1 = CliffGroup()
        end
        if nextCliff == 2 then
            cliff2 = CliffGroup()
        end
        if nextCliff == 3 then
            cliff3 = CliffGroup()
        end
        
        nextCliff = nextCliff + 1
        
        if nextCliff == 4 then
            nextCliff = 1
        end
        
        cliffTimer = 0
    end
 
   --handle touches
    for k,touch in pairs(touches) do
        SlappyTouched(touch)
        HappyTouched(touch)
    end
       
            
end

function touched(touch)
    if touch.state == ENDED then
        touches[touch.id] = nil
    elseif touch.state == BEGAN then
        touches[touch.id] = touch
    end
end

function collide(contact)
    if contact.state == BEGAN then 
        print("HIT!")
    end
end


Cliff = class()
    
function Cliff:init(y,h)
    local w = cliffWidth

    self.x = WIDTH + cliffWidth
    self.y = y
    self.w = cliffWidth
    self.h = h
    
    self.cliffBody = physics.body(POLYGON, vec2(-w/2,h/2), vec2(-w/2,-h/2), vec2(w/2,-h/2), vec2(w/2,h/2))
    self.cliffBody.x = self.x
    self.cliffBody.y = self.y
    
    -- debugPhysics:addBody(self.cliffBody)
end


function Cliff:draw()
    self.cliffBody.x = self.cliffBody.x + scrollSpeed
    sprite("Platformer Art:Block Brick",self.cliffBody.x,self.cliffBody.y,self.w,self.h)
    -- debugPhysics:draw() 
    if self.cliffBody.x < 200 then
        self.cliffBody.destroy()
    end
end

CliffGroup = class()

function CliffGroup:init()
    -- determine the type of cliff this will be
     cliffType = 1 --math.random(1)
    
    -- 1 is a cliff with the holes up top
    -- if cliffType == 1 then
        self.TopCliff1 = Cliff(HEIGHT-HEIGHT/20,HEIGHT/10)
        self.TopCliff2 = Cliff(HEIGHT-HEIGHT/2.3,HEIGHT/10)
        self.TopCliff3 = Cliff(HEIGHT/7,HEIGHT/4.5)    
    -- end
    
end

function CliffGroup:draw()
    -- Codea does not automatically call this method
    self.TopCliff1:draw()
    self.TopCliff2:draw()
    self.TopCliff3:draw()
end

function CliffGroup:touched(touch)
    -- Codea does not automatically call this method
end

@MrScience101 You have made the annoying error of mistaking the : for an .
It would be physics.body:destroy()
I would set the body to nil before destroying it too.

I can’t believe I did that again. If I remember right you solved the same exact problem I had last time I posted a problem like this. That brings you up to what now? Three million free points :). Thank you so much, can’t believe I wasted three hours trying all sorts of variations.

@MrScience101 don’t worry we all face that mistake at the start. I kept mistaking a . in pos.x for pos,x and coding for a while before even running the project then not finding that comma for about half an hour!

@MrScience101 And I can’t read the documentation correctly to realize that a DISTANCE joint requires 4 parameters instead of 3. I think everyone stumbles every now and then, and then, and then.

I don’t think I’ll ever stop making mistakes, even today I tried putting a table in place of a vec2 instead of putting .pos after the table, took me 5 minutes of just staring at the screen.