Issue with surface.DrawPoly in VGUIs

So, I have a notification system that can display multiple notifications at a time.
Notification function


-- Draws and animates CAH notifications.
function CAH:Notify( message, icon, noSound )
	icon = icon or "cah/bell64.png"

	local SCREEN_X, SCREEN_Y = ScrW() / 1920, ScrH() / 1080

	local panel = vgui.Create("CAH_Notification")
	panel:SetAlpha(0)
	panel:SetText(message)
	panel:SetIcon(icon)
	panel:SetPos(-panel:GetWide() - 10, SCREEN_Y * 25)

	panel:MoveTo(SCREEN_X * 25, SCREEN_Y * 25, 0.5, 0.45, 5)
	panel:AlphaTo(255, 0.5, 0.5)

	panel:AlphaTo(0, 1, 0.5 + self.CVAR.notiftime:GetInt(), function( animData, panel )
		table.RemoveByValue(self.notifications, panel)
		panel:Remove()
	end)

	for k, notif in pairs(self.notifications) do
		local x = (#self.notifications + 1 - k) * SCREEN_Y * 70 + SCREEN_Y * 25
		notif:MoveTo(SCREEN_X * 25, x, 0.4, 0, 10)
	end

	table.insert(self.notifications, panel)

	MsgC(Color(68, 142, 253), "[CAH] "..message.."
")

	if (not noSound and self.CVAR.playsound:GetBool()) then
		timer.Simple(0.45, function()
			surface.PlaySound("cah/notification.wav")
		end)
	end
end

Notification VGUI


local PANEL = {}

function PANEL:Init()
	local SCREEN_Y = ScrH() / 1080

	self.text = "No Message..."
	self.iconMat = Material("cah/bell64.png")

	self:SetSize(self:GetWide(), SCREEN_Y * 50)
end

function PANEL:Paint( w, h )
	local triangle = {
		{x = 0, y = h / 2},
		{x = 10, y = h / 3},
		{x = 10, y = h / 1.5}
	}

	surface.DisableClipping(true)

	surface.SetDrawColor(Color(68, 142, 253))
	surface.DrawPoly(triangle)
	surface.DrawRect(10, 0, 100, h)

	surface.SetDrawColor(color_white)
	surface.SetMaterial(self.iconMat)
	surface.DrawTexturedRect(35, 0, h, h)

	surface.DrawRect(110, 0, w - 110, h)

	surface.SetFont("CAH_TitleFont")
	surface.SetTextColor(Color(68, 68, 68))
	surface.SetTextPos(130, 13)
	surface.DrawText(self.text)

	surface.DisableClipping(false)
end

function PANEL:GetWide()
	surface.SetFont("CAH_TitleFont")
	local textW, textH = surface.GetTextSize(self.text)

	return 150 + textW
end

function PANEL:SetText( text )
	self.text = text
	self:SetWide(self:GetWide())
end

function PANEL:SetIcon( icon )
	self.iconMat = Material(icon)
end

vgui.Register("CAH_Notification", PANEL, "DPanel")

My issue is that the triangle supposed to be on the right only appears on the oldest active notification as seen in the video.

If you want to see more code from the project: GitHub.

Try doing draw.NoTexture() before the DrawPoly call.

[editline]15th September 2015[/editline]

This sort of behavior usually is due to multiple panels sharing the same variables unintentionally, but I don’t see such problem in your code.

Thanks, that fixed it.