Skip to content

🐞 Fix crash when a cycle action has an empty cycle#1115

Open
bit-saver wants to merge 1 commit into
mrkai77:developfrom
bit-saver:fix/empty-cycle-crash
Open

🐞 Fix crash when a cycle action has an empty cycle#1115
bit-saver wants to merge 1 commit into
mrkai77:developfrom
bit-saver:fix/empty-cycle-crash

Conversation

@bit-saver

Copy link
Copy Markdown
Contributor

Summary

A cycle action configured with an empty cycle list crashes Loop with EXC_BREAKPOINT (SIGTRAP) — an out-of-bounds array access.

Root cause

LoopManager.getNextCycleAction guards action.cycle against nil but not against an empty array, then does currentCycle[0] on the cycle-restart path and the "no current index" fallback. An empty cycle → currentCycle[0] traps.

Crash (abridged): EXC_BREAKPOINT in LoopManager.getNextCycleActionchangeActionopenLoop.

Fix

Guard against an empty cycle too, returning the action unchanged (there's nothing to advance to).

Testing

Built (Release). A cycle action with zero sub-actions no longer crashes; non-empty cycles are unaffected — the guard only changes the empty case.

`getNextCycleAction` indexes `currentCycle[0]` when restarting or when no
current index is found, but only guarded against a nil `cycle`, not an empty
one. A cycle action configured with zero sub-actions therefore traps
(EXC_BREAKPOINT) on the empty-array subscript. Guard against an empty cycle
and return the action unchanged.
guard let currentCycle = action.cycle else {
// An empty cycle has no actions to advance to; bail out instead of indexing
// into it — the `currentCycle[0]` accesses below would trap on an empty array
// (EXC_BREAKPOINT crash when a cycle action is configured with no sub-actions).

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a bit too verbose. It’s definitely a bug, but I think it’s already fairly clear what !currentCycle.isEmpty is trying to fix here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants