Search code examples
graphicslualove2dhexagonal-tiles

Drawing lines in love2d crashes program


I'm trying to draw a hexagonal grid with love2d using love.graphics.line but after drawing around 15000 lines the program crashes with only one message abort (core dumped).

function love.load()
    ww, wh = love.graphics.getDimensions()
    hexradius = 10
    size = 50

    hexgrid = newGrid(hexradius, size, size) 
end

function love.draw(dt)
    drawgrid()
end

function drawgrid()
    local jxOffset = hexgrid.rad * -math.tan(math.pi/1.5) 
    local ixOffset = jxOffset/4
    local iyOffet = jxOffset * math.sin(math.pi/3)


    for i=1,hexgrid.size.x do
        for j=1,hexgrid.size.y do
            love.graphics.push()
        
            love.graphics.translate(ixOffset + j * jxOffset, i * iyOffet)
            love.graphics.line(
                hexgrid.hex[1].x, hexgrid.hex[1].y,
                hexgrid.hex[2].x, hexgrid.hex[2].y,
                hexgrid.hex[3].x, hexgrid.hex[3].y,
                hexgrid.hex[4].x, hexgrid.hex[4].y,
                hexgrid.hex[5].x, hexgrid.hex[5].y,
                hexgrid.hex[6].x, hexgrid.hex[6].y,
                hexgrid.hex[1].x, hexgrid.hex[1].y)

            love.graphics.pop()
        end

        ixOffset = -ixOffset
    end
end

function newGrid(rad, xsize, ysize)
    local g = {
        rad = rad,
        hex = {},
        size = {
            x = xsize,
            y = ysize,
        },
    }

    for i=1,6 do
        local dir = math.pi/3 * (i+0.5)

        g.hex[i] = {}
        g.hex[i].x = g.rad * math.cos(dir)
        g.hex[i].y = g.rad * math.sin(dir)
    end

    return g
end

I'm quite new to love2d and graphical stuff in general so maybe I'm trying to draw a great amount of lines and it's just not possible, but the grid I'm generating does not appear to be that big. I'm using LOVE 11.3.

Thanks in advance!


Solution

  • As Luther suggested in a comment it's a bug in Löve. It's already fixed and will be available in the next release Löve 11.4.

    Thanks!