Skip to content

Fix exception in ArrayHierarchicalCollection.set() when parent branch is filtered. - #211

Closed
player-03 wants to merge 3 commits into
feathersui:masterfrom
player-03:ArrayHierarchicalCollection_set_exception
Closed

player-03 wants to merge 3 commits into
feathersui:masterfrom
player-03:ArrayHierarchicalCollection_set_exception

Conversation

@player-03

Copy link
Copy Markdown
Contributor

Without this, the following will crash because it can't find the original item.

final collection:ArrayHierarchicalCollection<TreeNode<Int>>
	= new ArrayHierarchicalCollection<TreeNode<Int>>([
	new TreeNode<Int>(1, [new TreeNode(1), new TreeNode(0), new TreeNode(2)]),
	new TreeNode<Int>(0, [new TreeNode(3), new TreeNode(3), new TreeNode(4)]),
	new TreeNode<Int>(5, [new TreeNode(0), new TreeNode(0), new TreeNode(1), new TreeNode(5)])
], (node:TreeNode<Int>) -> node.children);

trace(collection.get([0, 1]).data + " == " + 0);
trace(collection.get([1, 1]).data + " == " + 3);

collection.filterFunction = (node:TreeNode<Int>) -> node.data != 0;
trace(collection.get([0, 1]).data + " == " + 2);
trace(collection.get([1, 1]).data + " == " + 5);

collection.set([0, 0], new TreeNode(4));
trace(collection.get([0, 0]).data + " == " + 4);

collection.set([1, 1], new TreeNode(100)); //ArrayHierarchicalCollection.hx:269: characters 19-46 : Uncaught exception Negative array index: -1
trace(collection.get([1, 1]).data + " == " + 100);

collection.filterFunction = null;
trace(collection.get([1, 1]).data + " == " + 3);

I was trying to prove it'd write to the unfiltered [1, 1] location, but it didn't even get that far.

@player-03

Copy link
Copy Markdown
Contributor Author

I'm not sure if this is the best solution. It takes an extra findBranchChildren() call to get the parent FilterAndSortItem.

Maybe instead we could store the original parent array and index in that? This item was found at this index of this source array. Then that's just known, there's no need to rely on unfilteredLastLocationIndex = branchChildren.indexOf(oldItem) with its potential to return -1.

@joshtynjala

Copy link
Copy Markdown
Member

ArrayHierarchicalCollection.hx:269: characters 19-46 : Uncaught exception Negative array index: -1

Weirdly, I'm not able to reproduce this exact exception on a variety of targets that I tried. Most targets seem to throw no exception at all for me. I'm getting a SIGNAL11 from HashLink, though. No message with it. However, it does appear to be caused by the -1 index.

I can see that the logic is a bit wonky here. The call to this.findBranchChildren(this._array, this._itemToChildren, location); doesn't really make sense, since any part of the location array could have been filtered out, so it could be searching in a completely incorrect branch, causing the indexOf() to return -1. If it had found the correct branch, then it would be impossible for indexOf() to return -1.

I'll look into cleaning this up when I get a chance.

@player-03 player-03 mentioned this pull request Aug 8, 2026
@player-03

Copy link
Copy Markdown
Contributor Author

Closing this because I plan to submit a better solution as part of the other PR.

@player-03 player-03 closed this Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants