Skip to content

Fix ZeroDivisionError crash in Particle.update() (SLOP-450) - #1

Open
tosfos wants to merge 1 commit into
masterfrom
SLOP-450-zerodiv-particle-fade
Open

Fix ZeroDivisionError crash in Particle.update() (SLOP-450)#1
tosfos wants to merge 1 commit into
masterfrom
SLOP-450-zerodiv-particle-fade

Conversation

@tosfos

@tosfos tosfos commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • asteroids_game.py Particle.update() divided by zero once a particle's lifetime countdown reached 0, killing the whole game during normal play shortly after any asteroid explosion (explode() spawns particles with lifetimes of 20-40 frames).
  • Guard the fade computation: alpha is set to 0 once the particle expires, mirroring the existing safe pattern in particle.py.

Evidence

Verified empirically with a headless harness driving the actual class from this file (pygame-ce 2.5.8, Python 3.14):

  • Before: initial lifetime 25 -> frames 1-24 fine -> frame 25 raises ZeroDivisionError: division by zero.
  • After: particles run past expiry with no exception; final alpha is 0 as intended.

Fixes SLOP-450

Test plan

  • Harness: particle survives lifetime countdown to/below 0 without raising
  • python -m py_compile asteroids_game.py

…ches 0

Once a particle's countdown hit 0, the fade computation divided by zero,
crashing the game during normal play after asteroid explosions. Clamp
alpha to 0 once the particle is expired, matching the pattern already
used in particle.py.

Fixes SLOP-450

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1274696b-a9f1-4d1d-8f1e-0cc19f01d0c4


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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