#293 fixed race condition with graphics element IDs

This commit is contained in:
Mikayla Fischler
2023-07-19 11:27:33 -04:00
parent 681bb0963e
commit def02a94d2
6 changed files with 18 additions and 10 deletions

View File

@ -7,7 +7,7 @@ local flasher = require("graphics.flasher")
local core = {}
core.version = "1.0.1"
core.version = "1.0.2"
core.flasher = flasher
core.events = events

View File

@ -71,7 +71,8 @@ function element.new(args, child_offset_x, child_offset_y)
p_window = nil, ---@type table
position = { x = 1, y = 1 }, ---@type coordinate_2d
bounds = { x1 = 1, y1 = 1, x2 = 1, y2 = 1 }, ---@class element_bounds
next_y = 1,
next_y = 1, -- next child y coordinate
next_id = 0, -- next child ID
subscriptions = {},
mt = {}
}
@ -352,13 +353,14 @@ function element.new(args, child_offset_x, child_offset_y)
local child_element = child.get()
if key == nil then
table.insert(protected.children, child_element)
return #protected.children
else
protected.children[key] = child_element
return key
local id = key ---@type string|integer|nil
if id == nil then
id = self.next_id
self.next_id = self.next_id + 1
end
protected.children[id] = child_element
return id
end
-- remove a child element