Is draw_mesh broken , or am I doing something wrong?

Godot Version

4.2.2.stable.official

Question

Hello! I’ve encountered a problem whilst working on a pie chart, which is that I can’t use draw_mesh to draw a “feathering” primitive triangle strip like the source code does for anti-aliasing. I’ve done a minimal reproduction to showcase the problem.

It throws errors multiple times a second saying mesh_get_surface_count: Parameter "mesh" is null and links to this part of the source code:

Here is my code. The mesh is correct, since I can add it to a mesh instance, and then it works fine (shown in the commented part of the code).

extends Control

func _draw():
	var mesh = ArrayMesh.new()
	var mesh_vertices: PackedVector2Array = []
	
	var margin = 20
	
	mesh_vertices.append(Vector2(0 + margin, 0 + margin))
	mesh_vertices.append(Vector2(size.x - margin, 0 + margin))
	mesh_vertices.append(Vector2(0 + margin, size.y - margin))
	
	var mesh_data = []
	mesh_data.resize(ArrayMesh.ARRAY_MAX)
	mesh_data[ArrayMesh.ARRAY_VERTEX] = mesh_vertices
	
	mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, mesh_data)
		
	var texture2d = preload("res://icon.svg")
	draw_mesh(mesh, texture2d) # doesn't work
	
	
	#var mesh_instance = MeshInstance2D.new()
	#mesh_instance.mesh = mesh

	#add_child(mesh_instance) # works, though duplicates every time there's a redraw

Thank you for any help. It’s sort of driving me insane.