Closed magroader closed 4 years ago
Thank you for the bug report! What is the best and easiest way to reproduce the problem?
Here is my basic setup:
local list = gooey.dynamic_list(list_id, list_stencil, list_item_template, items)
for i,item in ipairs(list.items) do
if item.data then
-- populate my gui nodes with data from item.data
end
end
If items
has anything in it during one call to this, then later items
has everything removed from it, then you will still get into the inner if
statement, but with stale data that used to be, but is no longer, in the items
list.
The gui does get disabled in this case, so the stale data isn't actually visible. However, the inner check does happen, so I need to actually detect that the data is stale (and not do anything that might crash).
The only reason I even noticed this was because I had a list of guid keys that I was using, and I was populating the gui based on data retrieved from a separate system keyed off those guids. The data retrieval returned nil
(because the data had been removed), I tried to pass nil
to a gui.set_text()
call, and it crashed. I eventually traced it back to gooey
giving me the stale data despite that data NOT being in the items
list I passed.
I worked around it by doing this:
if #items == 0 then
-- Bug in gooey if no items - it was keeping the item.data property around but invalid
-- https://github.com/britzl/gooey/issues/59
for i=1,#list.items do
list.items[i].data = nil
end
end
However, after submitting this bug, I found this ALSO happens when items are removed from an overly full list - I had like 10 things in my list, and I deleted a few, and during one of these deletions I once again hit a case where items.data
was stale. I suspect the overall list could hold N
items, and when dropping down to N-1
pieces of data, I started to get stale data that wasn't in the array passed.
Thanks, I'll look into it during the week.
Because of this early bail:
When the list had items but then became empty,
item.data
for items that previously had data stays what it was before.