Skip to content

Commit

Permalink
Avoid infinite loop (#44)
Browse files Browse the repository at this point in the history
* Avoid infinite loop

* Fix clippy

* Add error message

* Change to use log library
  • Loading branch information
MJohnson459 committed Jan 18, 2024
1 parent 672e101 commit 9c3e11c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -28,6 +28,7 @@ bvh2d = { version = "0.3", git = "https://github.com/mockersf/bvh2d" }
serde = { version = "1.0", features = ["derive"], optional = true }
spade = "2.2"
geo = "0.26.0"
log = "0.4"

[dev-dependencies]
criterion = "0.5"
Expand Down
7 changes: 6 additions & 1 deletion src/lib.rs
Expand Up @@ -29,6 +29,7 @@ use glam::Vec2;

use helpers::Vec2Helper;
use instance::{EdgeSide, InstanceStep};
use log::error;
#[cfg(feature = "tracing")]
use tracing::instrument;

Expand Down Expand Up @@ -293,13 +294,17 @@ impl Mesh {
start,
);

loop {
// Limit search to avoid an infinite loop.
for _ in 0..self.polygons.len() * 1000 {
match search_instance.next() {
InstanceStep::Found(path) => return Some(path),
InstanceStep::NotFound => return None,
InstanceStep::Continue => (),
}
}

error!("Search from {from} to {to} failed. Please check the mesh is valid as this should not happen.");
None
}

/// The delta set by [`Mesh::set_delta`]
Expand Down

0 comments on commit 9c3e11c

Please sign in to comment.