 
 		var elements = [BezierPathElement]()
 		var vertexCount: Int = 0
+		var elementCount: Int = 0
 
 		// due to limited memory resource, all vertexes may not be able to render at a time, but on the other hand, it should not render segment
 		// by segment because of performance.  Following code sprits line segments by vertex buffer's capacity.
 
 		for segment in segments {
 			let count = Int(segment.length / 2)
-			if vertexCount + count > vertexCapacity {
+			if vertexCount + count > vertexCapacity || elementCount + 1 > elementsCapacity {
 				elementsArray.append(elements)
 				elements = [BezierPathElement]()
 				vertexCount = 0
+				elementCount = 0
 			}
 			let element = BezierPathElement(type: segment.type, numberOfVertexes: count, vertexIndex: vertexCount, w1: w1, w2: w2,
 					p0: Point(segment.p0), p1: Point(segment.p1), p2: Point(segment.p2), p3: Point(segment.p3))
 			elements.append(element)
 			vertexCount += count
+			elementCount += 1
 		}
 		if elements.count > 0 {
 			elementsArray.append(elements)

				encoder.setRenderPipelineState(self.renderPipelineState)

				encoder.setFrontFacing(.clockwise)
				encoder.setVertexBuffer(vertexBuffer, offset: 0, at: 0)
				encoder.setVertexBuffer(uniformsBuffer, offset: 0, at: 1)

				encoder.setFragmentTexture(texture, at: 0)

		var uniforms = Uniforms(transform: transform, zoomScale: Float(context.zoomScale))
		let uniformsBuffer = device.makeBuffer(bytes: &uniforms, length: MemoryLayout<Uniforms>.size, options: MTLResourceOptions())

		// double buffer technique
		let elementsBuffers: [MTLBuffer] = [
				device.makeBuffer(length: MemoryLayout<BezierPathElement>.size * elementsCapacity, options: [.storageModeShared]),
				device.makeBuffer(length: MemoryLayout<BezierPathElement>.size * elementsCapacity, options: [.storageModeShared])
		]
		let vertexBuffers: [MTLBuffer] = [
			device.makeBuffer(length: MemoryLayout<Vertex>.size * vertexCapacity, options: [.storageModePrivate]),
			device.makeBuffer(length: MemoryLayout<Vertex>.size * vertexCapacity, options: [.storageModePrivate])
		]


		for (index, elements) in elementsArray.enumerated() {
			let bufferIndex = index % 2 // double buffer

			let commandBuffer = context.makeCommandBuffer()

