Bug 223799

Summary: Lines rendered to canvas element with more than 256 points are rendered incorrectly
Product: WebKit Reporter: James White <james.offwhite>
Component: CanvasAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: dino, james.offwhite, paul.neave, sabouhallawa, simon.fraser, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: Safari 14   
Hardware: iPhone / iPad   
OS: iOS 14   
Attachments:
Description Flags
two lines drawn on canvas, the bottom line has 267 points none

Description James White 2021-03-26 08:48:11 PDT
Created attachment 424361 [details]
two lines drawn on canvas, the bottom line has 267 points

Lines rendered to canvas element with more than 256 points are rendered incorrectly.

If I render a single line with 256 points the line renders as expected.

If I render a single line with more than 256 points the line is broken into two or more separate lines.

The following JS fiddle shows two lines, the top line has 256 points, the bottom line has 257 points. They are otherwise identical.

The bottom one consistently renders in 3 parts on ipad.

https://jsfiddle.net/g26t8adL/2/

For clarity, the code to reproduce is below

HTML:

<canvas id="c"></canvas>

JS:

(function() {
  // prep canvas
  let canvas = document.getElementById('c')
  let ctx = canvas.getContext('2d')
  canvas.width = 700
  canvas.height = 300
  
  // prep stroke
  ctx.globalAlpha = 0.5
  ctx.lineWidth = 30
  ctx.lineJoin = ctx.lineCap = 'round'
  
  // draw 256 point on canvas
  ctx.beginPath()
  for(let i=0; i< 256; i++){
    ctx.lineTo((50+(i*2)), 100)
  }
  ctx.stroke()
  
  // draw 257 point on canvas
  ctx.beginPath()
  for(let i=0; i< 257; i++){
    ctx.lineTo((50+(i*2)), 200)
  }
  ctx.stroke()
})();
Comment 1 Radar WebKit Bug Importer 2021-03-26 16:56:22 PDT
<rdar://problem/75907512>