UIListLayout sort function is unstable! Unable to find object Egg6 using binary search, had to resort to linear search
Resorts to no sorting from what I can see
UIListLayout sort function is unstable! Unable to find object Egg6 using binary search, had to resort to linear search
Resorts to no sorting from what I can see
Bump, still happening
I’m getting this too when I set Visible to false on an object in the list.
Not sure why it is complaining
I’m not able to reproduce this. What sort order do you have set? How are you destroying it? Just calling Destroy on the parent GuiObject?
I got this when my sort function wasn’t perfect and I removed a frame. When I fixed my sort function, this error didn’t appear anymore.
(Also, I was using UIGridLayout instead of UIListLayout)
I figured out why this happens lol
It’s when the custom sort function tries to compare an object with itself; so if you were to return true when obj1 == obj2, the warning would show up if that object was not visible.
So to fix it you could write: if obj1 == obj2 then return false end
I just didn’t expect the object to compare with itself
Yeah, writing a stable sort function is slightly nontrivial. This warning is supposed to help with debugging that. The wiki has some notes I wrote on some of the constraints to writing stable sort functions, I’ll make sure to add one about objects comparing equal to themselves.
I’ll post my code here later to confirm however would comparing itself not be a bug?
The sort function may compare an object to itself, may compare objects that are no longer in the layout / have been destroyed entirely, may compare objects that have not yet been inserted into the layout.
All but yet to be inserted make no sense, why would they ever need to be compared as they are either no longer in the list or trying to compare an object with itself which the result would make no difference for
Because to remove an object that has been destroyed, it must be located within the list. Objects can be compared against themselves because no assumptions about the ordering are made by the sorting algorithm. It does not assume elements are equal to themselves if they have object identity equality.
Sorry, I’m not understanding:
If the object is destroyed why would anything need to be compared to it as the object is no longer part of the GUI and thus can’t be before or after any other objects? Could this not be assumed to always be false and skip the sorting function?
Why would it need to compare an object with itself? If anything other then false errors why not just skip calling the sorting function and assume false to avoid these errors?