Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: If dynamic list becomes empty, items have invalid data attached #59

Closed
magroader opened this issue Jul 26, 2020 · 3 comments
Closed

Comments

@magroader
Copy link

Because of this early bail:

	-- bail early if the list is empty
	if list.data_size == 0 then
		if refresh_fn then refresh_fn(list) end
		return list
	end

...

	update_dynamic_listitem_data(list)

When the list had items but then became empty, item.data for items that previously had data stays what it was before.

@britzl
Copy link
Owner

britzl commented Jul 27, 2020

Thank you for the bug report! What is the best and easiest way to reproduce the problem?

@magroader
Copy link
Author

magroader commented Jul 28, 2020

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.

@britzl
Copy link
Owner

britzl commented Aug 16, 2020

Thanks, I'll look into it during the week.

@britzl britzl closed this as completed in 1eb683f Aug 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants