caewok / fvtt-elevation-ruler

Modifies Foundry VTT ruler to display when dragging tokens, add token speed highlighting, do pathfinding, calculate elevation
MIT License
12 stars 13 forks source link

[BUG] 'elevation: must be a finite number' Error #38

Closed Larkinabout closed 6 months ago

Larkinabout commented 7 months ago

Elevation Ruler 0.8.2 Foundry VTT 11.315 dnd5e 2.4.1

  1. Use 'Gridless' for the scene.
  2. Enable 'Prefer Token Elevation'.
  3. Move token and create at least one waypoint.
  4. See error.

The error is thrown with the token update in _animateSegment due to segment.ray.B.z having a value of 'NaN'. I haven't been able to spend enough time with the code to work back to where segment.ray.B.z is written. image

Larkinabout commented 7 months ago

Same error seems to happen for gridded, although the distance tracking and elevation control also bugs out so there may be wider issues with gridded and the 'Prefer Token Elevation' option: image

Larkinabout commented 7 months ago

It's possible to resolve by checking whether elevationAtWaypoint(this.waypoints[this.waypoints.length - 1]) will resolve to a number. Though I'm not sure whether it should be resolve somewhere else by setting _terrainElevation in the absence of other elevation sources.

Nevertheless, here's the potential fix:

export function terrainElevationAtPoint(p, { startingElevation } = {}) {
  const measuringToken = this._getMovementToken();
  const waypointElevation = (this.waypoints.length) ? elevationAtWaypoint(this.waypoints[this.waypoints.length - 1] : null;
  startingElevation ??= isFinite(waypointElevation)
    ? waypointElevation : measuringToken
      ? tokenElevation(measuringToken) : Number.NEGATIVE_INFINITY;

  return elevationAtLocation(p, measuringToken, startingElevation);
}
caewok commented 6 months ago

Should be fixed in v0.8.3. Thanks! I refactored quite a bit of the terrain elevation code, which was quite old at this point.