diff --git a/ChangeLog.md b/ChangeLog.md index a700b072b..0a890109b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -178,6 +178,7 @@ Nazara Engine: - Added Collider2D::ForEachPolygon method - Added RigidBody::[Get|Set]PositionOffset allowing set an offset between body logic position and body physics position (center of mass position) - ⚠ Default TextureSampler WrapMode is now Clamp (instead of Repeat) +- Fixed StateMachine ignoring transitions made in Enter/Leave events of states Nazara Development Kit: - Added ImageWidget (#139) diff --git a/SDK/include/NDK/StateMachine.inl b/SDK/include/NDK/StateMachine.inl index 1b2a625ab..ba2a74928 100644 --- a/SDK/include/NDK/StateMachine.inl +++ b/SDK/include/NDK/StateMachine.inl @@ -159,8 +159,13 @@ namespace Ndk */ inline bool StateMachine::Update(float elapsedTime) { - for (StateTransition& transition : m_transitions) + // Use a classic for instead of a range-for because some state may push/pop on enter/leave, adding new transitions as we iterate + // (range-for is a problem here because it doesn't handle mutable containers) + + for (std::size_t i = 0; i < m_transitions.size(); ++i) { + StateTransition& transition = m_transitions[i]; + switch (transition.type) { case TransitionType::Pop: