Panel.GetHTMLMaterial() returns nil

I need this function to draw a 3D HTML plane, but everytime I use it gives me the error “IMaterial expected, got nil”, does anybody have this problem?


function ENT:DrawTheater()

	cam.Start3D2D( self:GetPos() + ( self:GetForward() * ( Lounge.TheaterWidth / -2 ) / Lounge.Scale ) + ( self:GetRight() * ( Lounge.TheaterHeight/ -2 ) / Lounge.Scale ), self:GetAngles(), Lounge.TheaterRes )
		
		surface.SetDrawColor( 0, 0, 0, 255 )
		surface.DrawRect( 0, 0, ( Lounge.TheaterWidth / Lounge.TheaterRes ) / Lounge.Scale, ( Lounge.TheaterHeight / Lounge.TheaterRes ) / Lounge.Scale )
		
		if Lounge.TheaterScreen and IsValid( Lounge.TheaterScreen ) and Lounge.TheaterScreen:GetHTMLMaterial() then
		
			surface.SetDrawColor( 255, 255, 255, 255 )
			surface.SetMaterial( Lounge.TheaterScreen:GetHTMLMaterial() )
			surface.DrawTexturedRect( 0, 0, ( Lounge.TheaterWidth / Lounge.TheaterRes ) / Lounge.Scale, ( Lounge.TheaterHeight / Lounge.TheaterRes ) / Lounge.Scale )
		
		end
	
	cam.End3D2D()
	
end

Just made something very similar to what you want recently. Sometimes the material is nil during page loads, so you just have to make sure it’s not nil before drawing. Hope the code provides you a nice base to work off of.

Thank you blackops.