What could cause the parameter of a function, used in a table.sort(..., function), to have a nil parameter?
In one of my sorts in TextureIt I just encountered an error "Attempt to index a nil value" and I'm not sure how it is happening. It is random, it isn't tied to any specific search. For example I've just been searching "open" & "close" (without quotes). I just keep reloading the ui and doing the searches, sometimes both searches work, sometimes the second parameter passed to the sort function is nil.
I tried saving a reference to the table I'm sorting & examining it with /zgoo whenever the error occurs, but it looks ok to me?
-- When I get an error I checked the table with /zgoo
-- to make sure contents look ok, everything looks fine.
someTempTable = searchResults
localfunction tableSort(tableA, tableB)
-- tableA is always ok
ifnot tableA then d("Not tableA")end
-- tableB is nil "sometimes"
ifnot tableB then d("Not tableB")end
-- error: "Attempt to index a nil value" (tableB is nil)
if tableA.text <= tableB.text thenreturntrueend
returnfalse
end
table.sort(searchResults, tableSort)
...
end
I'm not sure if this part has anything to do with it, but I'll include it anyways. This is where the searchResults table gets populated. I pass in a destination table (searchResults) to save the matches into because of the recursion. So I don't have to copy the returned results each time the recursion happens.