• 2D
  • Polygon2D red error message

I'm getting a red error message that points to C++ source code but doesn't give me a reference to my actual GDScript code, some I have a problem with determining what's the problem. I think it might have to do with collision, as it triggers when an enemy is attacking the player.

E 0:17:11.236 notification: Condition "idx < 0 || idx >= points.size()" is true. Continuing. <C++ Source> scene/2d/polygon_2d.cpp:330 @ notification()

I'm not really at home in the source code, and can't really make sense of what's going wrong. Source code referenced:

for (int j = 0; j < ic; j++) { int idx = r[j]; ERR_CONTINUE(idx < 0 || idx >= points.size()); tmp_points.write[j] = points[r[j]]; }

Hi,

From what I understand it seems there is index pointing to non-existing point in your polygon.

When you want to draw some polygon you will need in most cases 2 buffers. One will be holding unique points (locations) that are used in your polygon. Second one will hold indexes pointing to point (from first buffer) that should be drawn. That second buffer can be larger than first one and it will decide how many polygons you will draw and also it will decide about order in which points are drawn. That way you don't need to hold duplicate of points when you draw polygon using the same point more than once (so instead of holding the same 2 x float location you hold just additional 1 int as index, that is space optimization also).

Now from this error it seems case is as follows (very simplified & pseudo code):

var points = [(0, 0), (0, 1), (1, 0)] #3 points with indexes 0, 1, 2
var indices = [0, 1, 2, 1, 2, 3] #6 indices - indexes pointing to points

for(index in indices):
	if(indices[index] <= 0 || indices[index] >= points.size()):
		#This error will be printed since value 3 in indices[5] is pointing to
		#points[3], but points.size() == 3, so max index is 2!
		print("ERROR!")
	#Some other stuff

Above simplified pseudo-code only explains what exactly happens.

Now what may be reason? If you create polygon from code that could be most possibly the way you create your polygons. If you use editor to create polygons maybe that could be some internal engine bug. Hard to judge without more information (like how you create your polygons? Issue happened after some specific operation done or was present from the beginning?)

5 days later

(Haven't had time for the project for a while)

I'm suspecting it has to do with a polygon somewhere in my player character, it only seems to trigger when I move (must have misinterpreted it previously, as I also move when being attacked :-) ).

All the collisionshapes I use in the player character are CapsuleShapes, either for Collision of the KinematicBody or for detection of to-hit areas (under a Area2D) for damage. I don't really define any of the points myself. I would also think there's not really an indice.

The player moves on the tilemap that also has collisions, and those have arrays containing the points, but went through all tiles in the tilemap, and they all check out with 4 points.

That's probably the hardest part of figuring this out, no stacktrace to the ingame object or node to give me an idea into which polygon I should be looking.

Right, it's from the Polygon2D, so I should look at the images I use, not the collision polygons. I do have one I turn off/on when I move. (One for idle, one for movement)

Fixed it, redid the polygon2D.

Did encounter another bug, where copying one of my existing polygon2D's and changing the UV rendered the polygon invisible, but only in Godot 3.3. Reopened the project in 3.2.3, perfectly visible there (below screenshots from 3.3 and 3.2.3 with same node selected and nothing changed), and then went back to 3.3 (I seem to get great performance benefit from the renewed 2D batching)

Had possibly another issue then where it had saved my preferred language and had lost track of my projects, so had to reimport into project overview. ?