2D3D + DrawPoly strangeness

I’ve recently discovered a bug in an addon I am working on… however, the bug doesn’t seem to be my fault. (Or, at least not completely)
I’ve made a test entity to show others what’s going on by copy/pasting some of my addons code.

sent_arc_testent.lua
[lua]
–These definitions are in case you don’t have ARCLib
ARCLib = ARCLib or {}
function ARCLib.ConvertColor(col)
–Some C++ defined functions return some sort of
assert( IsColor(col), “ARCLib.ConvertColor: I wanted a color, but I got some sort of weird “…type( col )…” thing…” )
return col.r, col.g, col.b, col.a
end
– And here’s my font
surface.CreateFont( “ARCPhoneSmall”, {
font = “Arial”,
size = 12,
weight = 200,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false
} )

ENT.Base = “base_anim”
ENT.Type = “anim”

ENT.PrintName = “2D3D Testing ent”
ENT.Author = “ARitz Cracker”
ENT.Category = “Test”
ENT.Contact = “aritz@aritzcracker.ca”
ENT.Purpose = “TEEEEEEEEEEEEEEEEEST”
ENT.Spawnable = true
ENT.AdminOnly = false

if SERVER then
AddCSLuaFile()
function ENT:Initialize()
self:SetModel( “models/props_junk/PopCan01a.mdl” )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
local phys = self:GetPhysicsObject()
if phys:IsValid() then
phys:Wake()
phys:SetMaterial( “metal” )
end
–self:SetSkin( 2 )
end
function ENT:SpawnFunction( ply, tr )
if ( !tr.Hit ) then return end
local blarg = ents.Create (“sent_arc_testent”)
blarg:SetPos(tr.HitPos + tr.HitNormal * 40)
blarg:Spawn()
blarg:Activate()
return blarg
end
else
ENT.txtcol = color_white
ENT._colortab = {“r”,“g”,“b”,“a”}
ENT._colortabvals = {0,0,0,1}
ENT._colormtab = {Color(255,0,0,255),Color(0,255,0,255),Color(0,0,255,255),Color(128,128,128,255)}
function ENT:Draw()
self:DrawModel()
self:DrawShadow( true )
cam.Start3D2D(self:GetPos(), self:GetAngles(), 0.23)
for i=1,4 do
h = 48 - 14
w = 122/4
x = 1 + w*(i-1)
y = 1 + 14
draw.SimpleText( self._colortabvals*, “ARCPhoneSmall”, x + w/2, y + h/2, self.txtcol,TEXT_ALIGN_CENTER , TEXT_ALIGN_CENTER )
surface.SetDrawColor(ARCLib.ConvertColor(self._colormtab*))

			local polytab = {}
			polytab[1] = {}
			polytab[1].x = x + w/2
			polytab[1].y = y + h - 2
			polytab[2] = {}
			polytab[2].x = x + w - 2
			polytab[2].y = y + h/2 + 7
			polytab[3] = {}
			polytab[3].x = x + 2
			polytab[3].y = y + h/2 + 7
			
			local polytab2 = {}
			polytab2[1] = {}
			polytab2[1].x = x + w/2
			polytab2[1].y = y + 2
			polytab2[2] = {}
			polytab2[2].x = x + w - 2
			polytab2[2].y = y + h/2 - 7
			polytab2[3] = {}
			polytab2[3].x = x + 2
			polytab2[3].y = y + h/2 - 7
			
			--draw.NoTexture()
			surface.DrawPoly(polytab2)
			--draw.NoTexture()
			surface.DrawPoly(polytab)
			

			surface.SetDrawColor(ARCLib.ConvertColor(self.txtcol))

			surface.DrawLine(polytab[1].x,polytab[1].y,polytab[2].x,polytab[2].y)
			surface.DrawLine(polytab[2].x,polytab[2].y,polytab[3].x,polytab[3].y)
			surface.DrawLine(polytab[3].x,polytab[3].y,polytab[1].x,polytab[1].y)
			

			surface.DrawLine(polytab2[1].x,polytab2[1].y,polytab2[2].x,polytab2[2].y)
			surface.DrawLine(polytab2[2].x,polytab2[2].y,polytab2[3].x,polytab2[3].y)
			surface.DrawLine(polytab2[3].x,polytab2[3].y,polytab2[1].x,polytab2[1].y)
		end
	cam.End3D2D()
end

end
[/lua]
Notice how the 2 NoTexture functions are commented out:

[lua]
–draw.NoTexture()
surface.DrawPoly(polytab2)
–draw.NoTexture()
surface.DrawPoly(polytab)
[/lua]
Result: (The green is completely filled in, blame gifcam)

http://www.aritzcracker.ca/uploads/aritz/result1.gif

The polys don’t render when I press C or open the Q menu

[lua]
draw.NoTexture()
surface.DrawPoly(polytab)
–draw.NoTexture()
surface.DrawPoly(polytab2)
[/lua]
Result:

http://www.aritzcracker.ca/uploads/aritz/result2.gif

[lua]
draw.NoTexture()
surface.DrawPoly(polytab)
draw.NoTexture()
surface.DrawPoly(polytab2)
[/lua]
Result:

http://www.aritzcracker.ca/uploads/aritz/result2.gif

(Yes, I know I linked the same file, but the result is the same)

Now, here’s the most confusing part

[lua]
draw.NoTexture()
surface.DrawPoly(polytab2) – I switched when the Polys are being rendered
–draw.NoTexture()
surface.DrawPoly(polytab)
[/lua]
Result:

http://www.aritzcracker.ca/uploads/aritz/result2.gif

:huh:
(Again, I know I linked the same file, but the result is the same)

[editline]17th September 2015[/editline]

Oh, and somewhat unrelated:
Shoving a nil value into DrawPoly causes GMod to eventually (after around a minute) crash with the vertex buffer size error.

[editline]17th September 2015[/editline]

Alright, so, thanks to this guy, I realized what the problem ones.

First off, I was too stupid to look BEHIND it

http://www.aritzcracker.ca/uploads/aritz/resultyay.gif

Turns out the points with the downward pointing triangle were defined in the wrong order :downs: