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: infinite loop in Zone:randomPosition when no valid tile exist #3178

Merged
merged 1 commit into from
Dec 14, 2024

Conversation

dudantas
Copy link
Member

Description

This commit fixes an infinite loop issue in the Zone:randomPosition function. When no valid positions (walkable tiles) exist in the zone, the function would previously enter an infinite loop. The updated logic now filters all positions upfront to identify walkable tiles, and if none are found, the function returns nil with appropriate logging. This change ensures better error handling and prevents server freezes due to infinite loops.

Behaviour

Actual

Calling Zone:randomPosition on a zone with no valid walkable positions causes an infinite loop, leading to a server hang.

Expected

Calling Zone:randomPosition on a zone with no valid walkable positions returns nil without entering an infinite loop, and logs the issue for debugging.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested

The changes were tested by creating zones with:

  1. No positions.
  2. Positions that are not walkable.
  3. A mix of walkable and non-walkable positions.

Test cases:

  • Zone with no positions returns nil and logs an error.
  • Zone with no walkable positions returns nil and logs an error.
  • Zone with valid walkable positions returns a random valid position.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I checked the PR checks reports
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

Added validation to filter valid positions before random selection in Zone:randomPosition. Ensures the function doesn't enter an infinite loop by checking for walkable tiles upfront and returning nil if no valid positions are available.
@dudantas dudantas force-pushed the dudantas/fix-infinity-loop-with-zone branch from 9efb2e0 to 75f510d Compare December 14, 2024 03:34
@dudantas dudantas changed the title fix: infinite loop in Zone:randomPosition when no valid positions exist fix: infinite loop in Zone:randomPosition when no valid tile exist Dec 14, 2024
@dudantas dudantas merged commit 61c1fc0 into main Dec 14, 2024
27 checks passed
@dudantas dudantas deleted the dudantas/fix-infinity-loop-with-zone branch December 14, 2024 04:53
vllworldbuilding pushed a commit to vllworldbuilding/canary that referenced this pull request Dec 15, 2024
…pentibiabr#3178)


This commit fixes an infinite loop issue in the `Zone:randomPosition`
function. When no valid positions (walkable tiles) exist in the zone,
the function would previously enter an infinite loop. The updated logic
now filters all positions upfront to identify walkable tiles, and if
none are found, the function returns `nil` with appropriate logging.
This change ensures better error handling and prevents server freezes
due to infinite loops.
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