Added debug checks to gl calls