EcsRx / ecsrx

A reactive take on the ECS pattern for .net game developers
MIT License
506 stars 36 forks source link

Removing entities during certain system handler setup processes causes missing key exceptions #37

Closed grofit closed 1 year ago

grofit commented 1 year ago

It was reported that due to the way certain system handlers enumerate and setup subscriptions for observables you could have a system added which starts up and processes the entities associated but they get removed when processing which triggers the OnEntityRemoved event which then wants to clean up the associated entity subscriptions in the handler, the problem here being the ProcessEntity methods are generally not finished by this point so subscriptions are not added to the dictionaries.

To side step this we pre-enumerate the observable groups (to bypass underlying enumerator change exceptions) and then pre-emptively create CompositeDisposable sub containers to be added to the sub lists before the processing happens, this now solves the issues for IReactToEntitySystem, IReactToDataSystem and ISetupSystem.

grofit commented 1 year ago

This has been fixed and pushed as of #35