Byteron / haldric-next

45 stars 6 forks source link

Execution Flow #83

Closed Byteron closed 2 years ago

Byteron commented 2 years ago

This PR adds deferred calls in some places for better execution flow. This should help with some bugs we had related to async world changes that caused bugs like the leaked entity exception, possibly others.

There are basically two changes in here. 1) GameStateController.PopState and PushState now don't immediately change the state, but wait until the end of the frame. That way, all systems of a state run through one before changing to a different state, so there is no state changes mid-system run that might cause issues like components bleeding into the next state because event systems that would have happened later in the frame are not executed anymore.

2) a CallDeferred in PlayState, when receiving state changes from nakama. Since this happens async, it might happen that entities are spawned in the middle of running the according event system. when an entity is added async while a system finishes, before a component is added, then it causes the leaked entity exception we had a bunch of times. Hopefully this PR fixes this issue without having to disable the check entirely.