-
-
Notifications
You must be signed in to change notification settings - Fork 113
Description
EntertainmentLayer inherits from List<EntertainmentLight>, exposing direct access to its own storage. However, within AutoCalculateEffectUpdate, it delegates work to another thread through Task.Run and reads through the same storage that it exposes without any locking mechanism. It does the same thing with Effects. If you call AutoCalculateEffectUpdate and later add an effect or remove a light, you may crash if the started task is reading at the same time you're writing.
Normally you could just add some locking around this, but since the storage mechanism is exposed, the user has no way to participate. I would have just submitted a PR, but I think the problem necessitates a breaking change to the API. I've done that in the past, but that was far earlier in the library's life so I wanted to start a discussion first as this same problem also occurs in other APIs.
I'd recommend avoiding inheriting directly from concrete collections for public API types in general, it locks you in to the type or forces you to make a breaking change if you have to change things later.