Added error checking code for triangle rendering.