Multi element physics static body, dynamic bodies pass through half the elements (same elements each time)

The following causes a strange result. Each tile has four elements to its static physics body.  The dynamic bodies that are dropped always pass through the top left and bottom right elements but respect the top right and bottom left elements.

Can anyone see why this is happening please?

[lua]
local physics = require( “physics” )

    

function dropBalls()

    balls = display.newGroup()

    for i=1,200,1 do

        posY = 15

        posX = math.random(display.contentWidth)

        ball = display.newCircle(posX,posY,15)

        ball:setFillColor(255,0,0)

        physics.addBody(ball,{radius=15})

    end

    balls:toFront()

    return true

end

function createTile(tileX,tileY)

    local rnd4 = math.random(16)

    --1 from 4 at random

    rnd4 = rnd4 / 4

    rnd4 = math.floor(rnd4)

    if rnd4 == 4 then rnd4 = 3 end

    rnd4 = rnd4 + 1

    tile = display.newRect(tileX,tileY,100,100)

    tile.strokeWidth = 5

    tile:setStrokeColor(0,0,0)

    tile.gateTop = false

    tile.gateRight = false

    tile.gateBottom = false

    tile.gateTop = false

    if rnd4 == 1 then 

        ---- gates (left and right)

        tile.gateLeft = true

        tile.gateRight = true

    end

    if rnd4 == 2 then 

        ---- gates (left and bottom)

        tile.gateBottom = true

        tile.gateLeft = true

    end

    if rnd4 == 3 then 

        ---- gates (left right and top)

        tile.gateLeft = true

        tile.gateRight = true

        tile.gateTop = true

    end

    if rnd4 == 4 then 

        ---- gates (all 4)

        tile.gateLeft = true

        tile.gateRight = true

        tile.gateTop = true

        tile.gateBottom = true

    end

    --make “tunnels” work#

    if tile.gateTop then

        --top right corner solid only

        topRight = {16,16,16,50,50,50,50,16}

    else

        --top right corner and top middle solid 

        topRight = {16,-16,16,50,50,50,50,-16}

    end

    if tile.gateLeft then

        --top left corner solid only

        topLeft = {16,-16,16,-50,50,-50,50,-16}

    else

        --top left and left middle solid 

        topLeft = {-16,-16,-16,-50,50,-50,50,-16}

    end

    if tile.gateRight then

        --bottom right corner solid only

        bottomRight = {-16,16,-16,50,-50,50,-50,16}

    else

        --bottom right and right middle solid 

        bottomRight = {16,16,16,50,-50,50,-50,16}

    end

    if tile.gateBottom then

        --bottom left corner solid only

        bottomLeft = {-16,-16,-16,-50,-50,-50,-50,-16}

    else

        --bottom left and bottom middle solid 

        bottomLeft = {-16,16,-16,-50,-50,-50,-50,16}

    end

        

    physics.addBody( tile, “static”,

        {shape=topLeft},

        {shape=topRight},

        {shape=bottomLeft},

        {shape=bottomRight}

    )

    

    return true

end

–init

physics.start()

physics.setDrawMode( “hybrid” )

for i=400,800,100 do

    for j=100,400,100 do

        createTile(j,i)

    end    

end    

timer.performWithDelay(1000,dropBalls)
[/lua]

hint: clockwise

Can verify that when the coordinates of the elements are specified in clockwise order physics body behaves correctly thanks.

hint: clockwise

Can verify that when the coordinates of the elements are specified in clockwise order physics body behaves correctly thanks.