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

fix: stack overflow in fill #614

Merged
merged 2 commits into from
Mar 9, 2025

Conversation

backwardspy
Copy link
Contributor

filling a large area (such as the entire screen starting from one of the corner pixels) can result in very deeply nested recursion in fill_rec, manifesting as a crash when calling fill(...) from python.

my approach to fixing this is to use a stack of coordinates to visit in a loop rather than recursing. this stack is initialised with a worst-case capacity of every pixel in the clipping region to avoid reallocs.

i've added a test that does a worst-case fill on a large canvas to validate the solution.

unrelated: while working on this i noticed that test_sound_set was failing. the sound instance in the test was missing the last two volumes & effects that were being asserted, so i added them to the .set(...) call. that change is in a separate commit from the fill_rec fix.

let me know what you think. thanks!

filling a large area (such as the entire screen starting from one of the
corner pixels) can result in very deeply nested recursion in `fill_rec`,
manifesting as a crash when calling `fill(...)` from python.

my approach to fixing this is to use a stack of coordinates to visit in
a loop rather than recursing. this stack is initialised with a
worst-case capacity of every pixel in the clipping region to avoid
reallocs.

i've added a test that does a worst-case fill on a large canvas to
validate the solution.
@backwardspy backwardspy changed the title Fix/fill stack overflow fix: stack overflow in fill Mar 6, 2025
@backwardspy
Copy link
Contributor Author

resolves #615

@kitao kitao changed the base branch from main to develop March 9, 2025 00:56
@kitao kitao merged commit 50e6033 into kitao:develop Mar 9, 2025
@kitao
Copy link
Owner

kitao commented Mar 9, 2025

Thank you!

@backwardspy backwardspy deleted the fix/fill-stack-overflow branch March 9, 2025 20:49
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