Prior to #256, mListDelegates iterators could only be invalidated by calls to operator() as all the other methods didn't remove list element. A recursive call to operator() could have still caused iterator invalidation.
This PR should address both issues by only removing list elements in operator() (and clear) and only while no other is doing the same. (It's still not thread safe, of course.)
I can't say I like the pattern of removing delegates from inside a delegate, but disallowing it is probably not an option. Likewise, switching to a vector and using an index based loop to prevent iterator invalidation while still allowing methods to remove delegates is probably not a good solution as it means delegates are no longer guaranteed to be invoked.
Fixes https://github.com/MyGUI/mygui/pull/256#issuecomment-1583264606
Prior to #256,
mListDelegates
iterators could only be invalidated by calls tooperator()
as all the other methods didn't remove list element. A recursive call tooperator()
could have still caused iterator invalidation.This PR should address both issues by only removing list elements in
operator()
(andclear
) and only while no other is doing the same. (It's still not thread safe, of course.)I can't say I like the pattern of removing delegates from inside a delegate, but disallowing it is probably not an option. Likewise, switching to a vector and using an index based loop to prevent iterator invalidation while still allowing methods to remove delegates is probably not a good solution as it means delegates are no longer guaranteed to be invoked.