Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timer event order pollution #1851

Merged
merged 4 commits into from
Oct 29, 2024

Conversation

avanwinkle
Copy link
Collaborator

This PR fixes a bug (found by https://groups.google.com/g/mpf-users/c/JtZxG7oOceQ/m/P3htggdmAwAJ) where the order of a Timer's control_events could cause a crash.

The Problem

There has been a longstanding (7+ years) flaw in the timer control event code where the event handler kwargs were a singleton dictionary, so each event handler would alter/amend the same dictionary and attach it as kwargs. This oversight slipped by largely unnoticed until earlier this year, when the timer code was revamped to pass more event kwargs through (to support dynamic placeholder values for tick value, tick interval, et cetera., see #1761).

Even then, this oversight slipped through because the timer kwarg pollution is dependent on the order in which the timer's control_events are listed. Only if a control event with a value comes before a reset/restart will the former event's timer_value kwarg be polluted into the reset/restart handler, causing a duplicate argument error.

The Fix

This PR simply moves the kwargs = {} declaration to be inside the control event iteration block, so each control event starts with a fresh, empty, unpolluted kwarg dictionary. With this change, the order of control events doesn't matter and pollution is avoided.

tick tock tick tock

Copy link

@avanwinkle avanwinkle merged commit 6441ddb into missionpinball:dev Oct 29, 2024
14 of 15 checks passed
@avanwinkle avanwinkle deleted the timer-event-order-pollution branch October 29, 2024 15:24
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