Skip to content

Reduce thread yield#5

Open
zhiyan114 wants to merge 8 commits intomasterfrom
qfix
Open

Reduce thread yield#5
zhiyan114 wants to merge 8 commits intomasterfrom
qfix

Conversation

@zhiyan114
Copy link
Copy Markdown
Member

Cut down "IO wait" time on main game thread.

Still doesnt resolve the random crash issue smh

@zhiyan114 zhiyan114 requested a review from Meowcaroni March 19, 2026 06:41
Comment thread src/display.c Outdated
Comment thread src/display.c
Comment thread src/main.c
Comment on lines +28 to +38
case STATE_PLAYING:
confirm_choice();
break;
case STATE_OVER_LOST:
start_game();
break;
case STATE_OVER_WIN:
break;
}
}
if(actionOpt == Action_Select && currentState == STATE_PLAYING)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Rapidly pressing the confirm button queues multiple actions. The sequential processing of these actions causes the result screen to be immediately overwritten by the new game screen.
Severity: HIGH

Suggested Fix

To prevent this, consider clearing the action queue after a significant state transition. For example, after processing an action that moves the game from STATE_PLAYING to STATE_OVER_LOST/STATE_OVER_WIN, call xQueueReset(actionQueue) to discard any stale, queued-up actions. Alternatively, add a state check before sending actions to the queue, or introduce a short delay or a "cooldown" state after showing the result screen to prevent immediate restarts.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/main.c#L28-L38

Potential issue: Due to the use of an action queue with a capacity of 8 and non-blocking
sends from button callbacks, rapid presses of the confirm button can queue multiple
`Action_Confirm` events. The `queueHandle` task processes these sequentially. The first
event triggers `confirm_choice()`, which displays the result screen and sets the state
to `STATE_OVER_LOST` or `STATE_OVER_WIN`. The loop immediately processes the next queued
`Action_Confirm`, which then calls `start_game()` based on the new state. This
overwrites the result screen with a new game screen, making the result screen flash for
only a few milliseconds or not appear at all.

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.

1 participant