setzer22/blackjack

Crash if creating circle with zero vertices

Trayshar opened this issue · 2 comments

Heya, just checking out this neat project of yours! I toyed around with circle vertice counts, hooked a bunch of 'em to a Scalar node to adjust all simultaneously. But then I slid below 3...

Steps to reproduce:

  • Create a new Scalar node with value 0
  • Create a Circle node
  • Connect the Scalar to the "num_vertices" input of the Circle node
  • Set Circle node to "active"
  • thread 'main' panicked at 'Circle construction should not fail: Cannot build meshes where polygons have less than three vertices.', blackjack_engine/src/mesh/halfedge/primitives.rs:91:14

Looks like a missing safety check somewhere, for when trying to set the value directly it won't go below 3. Also works with "Scalar Math" nodes (or anything else that outputs scalars I suppose)

Might make a PR for that since it seems fairly simple when I get around to it.

Oops, nice catch! The bounds enforced by the Circle node are bypassed if you plug in an input value from another node.

A good way to solve this would be to make the Rust functions responsible for building primitives fallible (by returning a Result, instead of unwrapping). This will turn the panic into a runtime error that would be shown on the UI.

This is a small refactor that needs to happen in primitives.rs, in the blackjack_engine crate. This would be a nice opportunity for a PR if you'd like to give this a go :)

Sure, I'm on it!