Resource ID out of range in SetResource (max is 1048575)
I have used Shapes to create (among other things) custom arrows which are build using an immediate mode script. The script takes two locations as an input, and then draws an arrow between the two.
After the arrows have been in use for a while, an error starts being created every few frames, see snip attached.
The Shape/Arrow still draws as expected, and I haven't observed any changes / impacts other than the error message spam.
Once this starts, only restarting the whole editor will stop the error from returning.
I have created a reproduction file which only needs Shapes, the arrow script and a test script which creates a bunch of arrows and randomises the origin and destination. To keep things simple, this test version doesn't use tweening/colours/etc (so there have been a few adjustments to the script), but the error still occurs. Also, the error typically takes upwards of an hour to occur naturally, but running this in play mode causes the error to occur within 2 minutes. Please let me know if there is somewhere I can send the reproduction file if that would assist.
The Arrow code is the below
using Shapes; using System.Collections.Generic; using UnityEngine; namespace Shapes { /// <summary> /// The Class which is causing the error - whenever this has changed enough times since the last unity restart /// </summary> /// [ExecuteAlways] public class ArrowDisplay : ImmediateModeShapeDrawer { public const float outerRadius = .5f; public const float innerRadius = outerRadius * 0.866025404f; public const float sqrtThreeOnTwo = 0.866025404f; public bool drawArrow = true; public bool rotate = true; [SerializeField] private Vector2 from = new Vector2(), to = new Vector2(); private Vector2 cachedFrom = new Vector2(), cachedTo = new Vector2(); private float headLength = 0.84f, headWidth = 0.2f, headTips = 0.1f, headCentre = 0.05f, tailWidth = 0.1f, tailStart = 0.1f, lineThickness = 0.05f, lineBendThickness = 0.4f; private float magnitude, rotation; private void OnValidate() { UnityEditor.EditorApplication.delayCall += _OnValidate; } private void _OnValidate() { SetPositions(from,to); } public void SetPositions(Vector2 _from, Vector2 _to) { from = _from; to = _to; if (_from == cachedFrom && _to == cachedTo) return; cachedFrom = _from; cachedTo = _to; Vector2 vector2 = to - from; rotation = Vector2.SignedAngle(new Vector2(0, 1), vector2); magnitude = vector2.magnitude; } public Vector2 Rotate(Vector2 _v, float _degrees) { float sin = Mathf.Sin(_degrees * Mathf.Deg2Rad); float cos = Mathf.Cos(_degrees * Mathf.Deg2Rad); float tx = _v.x; float ty = _v.y; _v.x = (cos * tx) - (sin * ty); _v.y = (sin * tx) + (cos * ty); return _v; } public override void DrawShapes(Camera _cam) { if (drawArrow) { using (Draw.Command(_cam)) { Draw.ResetAllDrawStates(); Draw.Rotate(Quaternion.Euler(90, 0, 0)); if (magnitude <= 0) return; Vector2 pos = new Vector2(transform.position.x, transform.position.z); List<vector2> vertices = new List<vector2>(); vertices.Add(new Vector2(0, magnitude)); vertices.Add(new Vector2(headWidth, magnitude - innerRadius * headLength - headTips)); vertices.Add(new Vector2(headCentre, magnitude - innerRadius * headLength)); vertices.Add(new Vector2(tailWidth, innerRadius * tailStart)); vertices.Add(new Vector2(-tailWidth, innerRadius * tailStart)); vertices.Add(new Vector2(-headCentre, magnitude - innerRadius * headLength)); vertices.Add(new Vector2(-headWidth, magnitude - innerRadius * headLength - headTips)); for (int i = 0; i < vertices.Count; i++) { if (rotate) vertices[i] = Rotate(vertices[i],rotation); vertices[i] = vertices[i] + from + pos; } PolygonPath gonPath = new PolygonPath(); PolylinePath linePath = new PolylinePath(); gonPath.AddPoints(vertices); linePath.AddPoints(vertices, thicknesses: new List<float> { lineThickness, lineThickness, lineThickness, lineThickness, lineThickness, lineThickness, lineThickness }); Draw.Polygon(gonPath); Draw.Polyline(linePath, true, thickness: lineBendThickness, joins: PolylineJoins.Round); } } } } } </float></vector2></vector2>
you need to dispose the polygon/polyline paths - have a look at the polyline section of the immediate mode documentation!