cleaned up rendering mode swapping

This commit is contained in:
2025-12-12 00:08:25 -05:00
parent 9d8f6aa60d
commit ec73d8c7c8
11 changed files with 1270 additions and 46 deletions

View File

@@ -399,6 +399,7 @@ function flexlove.beginFrame()
-- Cleanup elements from PREVIOUS frame (after they've been drawn)
-- This breaks circular references and allows GC to collect memory
-- Note: Cleanup is minimal to preserve functionality
-- IMPORTANT: Only cleanup immediate-mode elements, preserve retained-mode elements
if flexlove._currentFrameElements then
local function cleanupChildren(elem)
for _, child in ipairs(elem.children) do
@@ -408,17 +409,31 @@ function flexlove.beginFrame()
end
for _, element in ipairs(flexlove._currentFrameElements) do
if not element.parent then
-- Only cleanup immediate-mode top-level elements
-- Retained-mode elements persist across frames
if not element.parent and element._elementMode == "immediate" then
cleanupChildren(element)
end
end
end
-- Preserve top-level retained elements before resetting
local retainedTopElements = {}
if flexlove.topElements then
for _, element in ipairs(flexlove.topElements) do
if element._elementMode == "retained" then
table.insert(retainedTopElements, element)
end
end
end
flexlove._frameNumber = flexlove._frameNumber + 1
StateManager.incrementFrame()
flexlove._currentFrameElements = {}
flexlove._frameStarted = true
flexlove.topElements = {}
-- Restore retained top-level elements
flexlove.topElements = retainedTopElements
Context.clearFrameElements()
end