ClassyKit / Classy

Expressive, flexible, and powerful stylesheets for UIView and friends.
http://classykit.github.io/Classy/
MIT License
740 stars 77 forks source link

Fixes a crash caused by changing a hash table while it was being enumerated #91

Closed rafaelwinter closed 9 years ago

rafaelwinter commented 9 years ago

This problem happened when a thread was changing the scheduledItems hash table, while a timer triggered an update in another thread. This issue was very rare but caused a crash with an exception like

'Collection <NSConcreteHashTable: 0x170134640> was mutated while being enumerated'.

It was solved by guarding the code parts that read and modify the hash table with a @synchronized block.

cloudkite commented 9 years ago

@rafaelwinter Sorry for the delay in replying!

Classy should not be used across threads, since it updates UIKit objects which are not thread safe. Are you sure you are not triggering a classy style update on a background thread?

rafaelwinter commented 9 years ago

@cloudkite Hi Jonas, sorry for my really long delay. I had to work in other parts of our software and had to keep this on hold. Thanks for the tip about cross-thread updates. We were triggering UI updates from background, as you suspected. I surrounded my code on a GDC dispatch block to the main thread and worked fine.

Closing the PR now! Thanks a lot!