Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Certain values for scene tessellation throws an exception on WebGL

Discussion in '2D Experimental Preview' started by MaskedMouse, Mar 4, 2020.

  1. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,094
    We updated the Vector Graphics package to 2.0.0-preview.12
    However on a development build on our server it suddenly threw an exception about a
    runtime error: float unrepresentable in integer range


    We're generating bezier curves between connected nodes. But for some positions which seems to be when the points are almost equally in height it throws an exception on WebGL.

    I've made a reproduction project which uses the specific values that causes an exception.
    In the Editor it doesn't seem to be a problem.

    Edit: I just found out it has to do with it being a development build. A release build works just fine?

    Bug Report: 1225060

    The offending script:
    Code (CSharp):
    1. using System.Collections.Generic;
    2. using Unity.VectorGraphics;
    3. using UnityEngine;
    4.  
    5. public class SVGExceptionBug : MonoBehaviour
    6. {
    7.     public void Start()
    8.     {
    9.        var scene = CreateScene();
    10.        // Get the shape of the curve
    11.        var shape = scene.Root.Shapes[0];
    12.        // Get the shape contour
    13.        var contour = shape.Contours[0];
    14.        // Get the shape segments
    15.        var startSegment = contour.Segments[0];
    16.        var endSegment = contour.Segments[1];
    17.  
    18.        // Change the segments with the new information
    19.        // Our starting & end point
    20.        startSegment.P0 = new Vector2(788f, 45.3f);
    21.        endSegment.P0 = new Vector2(-561f, 44f);
    22.  
    23.        // Get the position of the tangent point relative to the parent of the start point. (which is the bezier generator itself)
    24.        startSegment.P1 = new Vector2(1530f, 45.3f);
    25.        startSegment.P2 = new Vector2(-1303f, 44.0f);
    26.  
    27.        // Set the segments as they're structs
    28.        contour.Segments[0] = startSegment;
    29.        contour.Segments[1] = endSegment;
    30.  
    31.        // Set contour
    32.        shape.Contours[0] = contour;
    33.  
    34.        // Create new geometry
    35.        var geoms = VectorUtils.TessellateScene(scene, new VectorUtils.TessellationOptions { StepDistance = 500, MaxCordDeviation = 0.1f, MaxTanAngleDeviation = 0.1f, SamplingStepSize = 0.01f });
    36.        Debug.Log(geoms[0].Vertices);
    37.     }
    38.  
    39.     private static Scene CreateScene()
    40.     {
    41.         return new Scene
    42.         {
    43.             Root = new SceneNode
    44.             {
    45.                 Shapes = new List<Shape>
    46.                 {
    47.                     new Shape
    48.                     {
    49.                         PathProps = new PathProperties
    50.                         {
    51.                             Stroke = new Stroke { Color = Color.red, HalfThickness = 1.0f }
    52.                         },
    53.                         Contours = new[]
    54.                         {
    55.                             new BezierContour
    56.                             {
    57.                                 Segments = new BezierPathSegment[2], Closed = false
    58.                             }
    59.                         },
    60.                         Fill = null
    61.                     }
    62.                 }
    63.             }
    64.         };
    65.     }
    66. }
     
    Last edited: Mar 4, 2020