Skip to content

Commit

Permalink
fix: memory leak in std.draw.poly
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoDornelles committed Oct 4, 2024
1 parent 6377d23 commit a5db785
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/lib/draw/poly.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,21 @@ local function decorator_triangle(func_draw_poly, std, func_draw_triangle)
end
end

local function decorator_poly(func_draw_poly, std, modes, repeats)
local function decorator_poly(func_draw_poly, std, modes, repeats)
local func_repeat = function(verts, mode)
if repeats and repeats[mode + 1] then
verts[#verts + 1] = verts[1]
verts[#verts + 1] = verts[2]
end
end

return function (engine_mode, verts, x, y, scale, angle, ox, oy)
if #verts < 6 or #verts % 2 ~= 0 then return end
local mode = modes and modes[engine_mode + 1] or engine_mode
local rotated = std.math.cos and angle and angle ~= 0
ox = ox or 0
oy = oy or ox or 0

if repeats and repeats[engine_mode + 1] then
verts[#verts + 1] = verts[1]
verts[#verts + 1] = verts[2]
end

if x and y and not rotated then
local index = 1
local verts2 = {}
Expand All @@ -69,6 +71,8 @@ local function decorator_poly(func_draw_poly, std, modes, repeats)
end
index = index + 1
end

func_repeat(verts2, engine_mode)
func_draw_poly(mode, verts2)
elseif x and y then
local index = 1
Expand All @@ -82,6 +86,8 @@ local function decorator_poly(func_draw_poly, std, modes, repeats)
verts2[index + 1] = yy
index = index + 2
end

func_repeat(verts2, engine_mode)
func_draw_poly(mode, verts2)
else
func_draw_poly(mode, verts)
Expand Down

0 comments on commit a5db785

Please sign in to comment.