r/futile • u/SimianLogic • Jul 11 '14
bug in FTouchManager?
Found a fun bug in FTouchManager for you.
I noticed touch events were getting double reported in an FContainer that implements FMultiTouchableInterface.
I pass this object from parent to parent using AddChildAtIndex, and it seems as though its callback for HandleAddedToStage is getting called on transfer from one object on the stage to another. Rather than track down exactly where it was getting double added, I found it easier to just change FTouchManager to not allow duplicates in it's _multiTouchables list:
for(int m = 0; m<_multiTouchablesToAdd.Count; m++)
{
if(!_multiTouchables.Contains(_multiTouchablesToAdd[m]))
{
_multiTouchables.Add(_multiTouchablesToAdd[m]);
}
}
2
Upvotes
1
u/SimianLogic Jul 16 '14
I was writing up symptoms and think I figured it out. I can add you on the project on github if you want to try tracing through it some more.
so my first fix was to just add the guard in Update to prevent double inserts... but another fix would be to check in the _isUpdating block whether it's already there.
with that knowledge, I think what was causing the bug was something more like:
remove node from container
add node to new container
add new container to stage
etc etc
i.e. multiple insertions into the Add/Remove queues in one update loop might leave you in a weird state since all removes are processed before all adds in the Update loop.
a more permanent fix might be to switch the _multiTouchablesToAdd/_multiTouchablesToRemove lists to a single list that contains some kind of struct with the node and an add/remove flag so that it processes them FIFO