Skip to content

Commit

Permalink
Only call state machine delegate function if delegate exists
Browse files Browse the repository at this point in the history
This should fix an issue where under certain conditions, stateChanges access states whose name seems to be returning nil. The stateChanges property is otherwise unused outside of this function. By adding this guard, stateChanges will not be used if the state machine delegate is unset.

This is a "quick fix" for an [issue](#330) in `rive-ios`. It seems that under certain conditions (tbd; still working with the developer to dig deeper). Somehow, the `.riv` animation seems to generate a state change whose name is `nil`, causing a crash in the `stateChanges` getter. This was initially attempted to be fixed by #7529.

Diffs=
19bda7a59 Only call state machine delegate function if delegate exists (#7541)

Co-authored-by: David Skuza <[email protected]>
  • Loading branch information
dskuza and dskuza committed Jul 9, 2024
1 parent d9f25cc commit 99b9a82
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1e7b1c0301a9fb9404798d5b4c0e7175d199659e
19bda7a59f824f0e28f84f6f61fcc319a5cecb33
5 changes: 4 additions & 1 deletion Source/RiveView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ open class RiveView: RiveRendererView {
}
}
isPlaying = stateMachine.advance(by: delta) && wasPlaying
stateMachine.stateChanges().forEach { stateMachineDelegate?.stateMachine?(stateMachine, didChangeState: $0) }

if let delegate = stateMachineDelegate {
stateMachine.stateChanges().forEach { delegate.stateMachine?(stateMachine, didChangeState: $0) }
}
} else if let animation = riveModel?.animation {
isPlaying = animation.advance(by: delta) && wasPlaying

Expand Down

0 comments on commit 99b9a82

Please sign in to comment.