<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>245145</bug_id>
          
          <creation_ts>2022-09-13 09:05:31 -0700</creation_ts>
          <short_desc>REGRESSION (iOS 16): Sequences of strokes in canvas may stroke with incorrect styles</short_desc>
          <delta_ts>2022-09-24 16:58:51 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>New Bugs</component>
          <version>Safari Technology Preview</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>245465</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>BrowserCompat, InRadar</keywords>
          <priority>P1</priority>
          <bug_severity>Major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Jason Merrill">jwmerrill</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>ap</cc>
    
    <cc>bfulgham</cc>
    
    <cc>ccampbell</cc>
    
    <cc>karlcow</cc>
    
    <cc>mattwoodrow</cc>
    
    <cc>paul.neave</cc>
    
    <cc>realer09</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>zalan</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1898261</commentid>
    <comment_count>0</comment_count>
      <attachid>462322</attachid>
    <who name="Jason Merrill">jwmerrill</who>
    <bug_when>2022-09-13 09:05:31 -0700</bug_when>
    <thetext>Created attachment 462322
Drawing two lines to canvas draws the second line with an incorrect stroke style

In Safari 16, on macOS 12.6 and iOS 16 Beta, certain sequences of stroke calls using the CanvasRenderingContext2D API stroke paths with incorrect properties.

This is a regression compared to Safari 15.

The attached example strokes two single-segment paths. Before the first stroke call, the strokeStyle is set to #f00 (red). Before the second stroke call, the strokeStyle is set to #000 (black). In most browsers, the second path is correctly stroked black, but in Safari 16, both paths are stroked red.

We have experimented with many minor variations of this problem. A few observations:
* strokeStyle is not the only affected property. lineWidth suffers from similar problems, and other properties may be affected too.
* The problem seems to depend on how many points are on the path. We have observed the problem with two point paths (i.e. single straight segments), but not with more complex paths.
* The problem seems to depend on attempting to set drawing context properties back to previously used values. In the attached example, the problem occurs when we attempt to set strokeStyle back to its default value (#000). This update is not applied when the path is stroked, and instead, the previous strokeStyle (#f00) is used.
* The problem seems to be affected by how clearRect calls are interleaved with stroke calls. Writes to strokeStyle or lineWidth (and perhaps other properties) appear not to be applied when they attempt to set a property back to the value it had at the time of the last clearRect call.
* We have reproduced similar problems with no clearRect calls at all, so the problem appears to be influenced by clearRect, but does not depend on clearRect.

We&apos;d be happy to supply additional variations on the attached example if it would be helpful.

The attached example is a reduced test case based on bugs reported to Desmos by iOS 16 Beta users using the Desmos Graphing Calculator (https://www.desmos.com/calculator). This bug report was jointly prepared by Jason Merrill and Julia Proft.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1898302</commentid>
    <comment_count>1</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2022-09-13 12:05:46 -0700</bug_when>
    <thetext>I am able to reproduce this bug in Safari 16 / STP 153 on macOS 12.6 and also on iOS 16 while other browsers like Chrome Canary 107 and Firefox Nightly 106 render horizontal line in ‘black’ color rather than ‘red’. Thanks!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1898327</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-09-13 13:43:51 -0700</bug_when>
    <thetext>&lt;rdar://problem/99886849&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1898328</commentid>
    <comment_count>3</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2022-09-13 13:43:58 -0700</bug_when>
    <thetext>Possibly regressed at https://commits.webkit.org/252522@main</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1898751</commentid>
    <comment_count>4</comment_count>
    <who name="Chris Campbell">ccampbell</who>
    <bug_when>2022-09-15 10:57:11 -0700</bug_when>
    <thetext>I believe this bug report accurately describes the graph rendering issues we&apos;re seeing in the En-ROADS climate simulator:
https://en-roads.climateinteractive.org/scenario.html

The issue causes lines to appear with the wrong color (e.g., the &quot;Baseline&quot; plot should always be black, not gray) and/or with the wrong stroke width (hovering over the &quot;Current Scenario&quot; blue plot sometimes causes it to appear thin instead of thick).

These issues were not present in Safari 15 or any other browser.  Only reproducible in Safari 16.0, Safari 16.1 beta1, and latest Safari Technology Preview (Release 153).

FWIW, we use Chart.js (https://github.com/chartjs/Chart.js) v2.9.4 for rendering graphs in En-ROADS.  While I don&apos;t have a smaller test case that reproduces this outside of En-ROADS/Chart.js, I hope you&apos;ll use En-ROADS to verify the fix for this regression.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1899762</commentid>
    <comment_count>5</comment_count>
    <who name="Bogdan Zhavraev">realer09</who>
    <bug_when>2022-09-20 03:22:39 -0700</bug_when>
    <thetext>Facing similar issue with Canvas not properly switching between stroke styles and line widths on Safari 16 (both MacOS and iOS). Hope my example helps to debug this issue.
https://jsfiddle.net/387t6cem/1/</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1899990</commentid>
    <comment_count>6</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2022-09-20 18:36:49 -0700</bug_when>
    <thetext>*** Bug 245420 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1900060</commentid>
    <comment_count>7</comment_count>
    <who name="Paul Neave">paul.neave</who>
    <bug_when>2022-09-21 01:15:34 -0700</bug_when>
    <thetext>(In reply to Simon Fraser (smfr) from comment #3)
&gt; Possibly regressed at https://commits.webkit.org/252522@main

Yes it could be that the batch optimizations/caching introduced here is overaggressive and has not been tested for all cases.

Until this is fixed, a hacky workaround is to adjust the lineWidth between each stroke to circumvent this &apos;caching&apos; behavior. For example:

```
context.lineWidth = 6;

context.beginPath();
context.strokeStyle = &apos;red&apos;;
context.moveTo(30, 50);
context.lineTo(50, 50);
context.stroke();

context.beginPath();
context.strokeStyle = &apos;blue&apos;;
context.moveTo(60, 50);
context.lineTo(80, 50);
context.stroke();

context.lineWidth = 6.001; // Small adjustment here or the next stroke will remain blue

context.beginPath();
context.strokeStyle = &apos;red&apos;;
context.moveTo(90, 50);
context.lineTo(110, 50);
context.stroke();
```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1900082</commentid>
    <comment_count>8</comment_count>
    <who name="Bogdan Zhavraev">realer09</who>
    <bug_when>2022-09-21 04:39:37 -0700</bug_when>
    <thetext>This workaround won&apos;t cover all bug cases.
In my example, i&apos;m always changing lineWidth along with strokeStyle, and yet bugs with invalid color or width are reproducible
(https://jsfiddle.net/387t6cem/1/)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1900955</commentid>
    <comment_count>9</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2022-09-24 16:58:51 -0700</bug_when>
    <thetext>We currently consider this to be a dupe of bug 245465. Sorry for duping to a newer bug, but that one has a PR already posted.

*** This bug has been marked as a duplicate of bug 245465 ***</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>462322</attachid>
            <date>2022-09-13 09:05:31 -0700</date>
            <delta_ts>2022-09-13 09:05:31 -0700</delta_ts>
            <desc>Drawing two lines to canvas draws the second line with an incorrect stroke style</desc>
            <filename>safari-16-draw-bug-stroke-style.html</filename>
            <type>text/html</type>
            <size>891</size>
            <attacher name="Jason Merrill">jwmerrill</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sPgo8aGVhZD4KICA8bWV0YSBjaGFyc2V0PSJ1dGYtOCI+CiAg
PG1ldGEgbmFtZT0idmlld3BvcnQiIGNvbnRlbnQ9IndpZHRoPWRldmljZS13aWR0aCI+CiAgPHRp
dGxlPlNhZmFyaSAxNiBjYW52YXMgYnVnIHN0cm9rZVN0eWxlPC90aXRsZT4KPC9oZWFkPgo8Ym9k
eT4KICA8cD5UaGVyZSBzaG91bGQgYmUgYSBkaWFnb25hbCByZWQgbGluZSBhbmQgYSBob3Jpem9u
dGFsIGJsYWNrIGxpbmUsIGJ1dCBpbiBTYWZhcmkgMTYsIGJvdGggbGluZXMgYXJlIHJlZC48L3A+
CiAgPHNjcmlwdD4KICAgIHZhciBjYW52YXMgPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KCdjYW52
YXMnKTsKICAgIGRvY3VtZW50LmJvZHkuYXBwZW5kQ2hpbGQoY2FudmFzKTsKICAgIHZhciBjdHgg
PSBjYW52YXMuZ2V0Q29udGV4dCgnMmQnKTsKCiAgICB2YXIgd2lkdGggPSAzMDA7CiAgICB2YXIg
aGVpZ2h0ID0gMzAwOwogICAgY2FudmFzLndpZHRoID0gd2lkdGg7CiAgICBjYW52YXMuaGVpZ2h0
ID0gaGVpZ2h0OwoKICAgIGN0eC5jbGVhclJlY3QoMCwgMCwgd2lkdGgsIGhlaWdodCk7CgogICAg
Ly8gZHJhdyByZWQgbGluZQogICAgY3R4LnN0cm9rZVN0eWxlID0gIiNmMDAiOwogICAgY3R4LmJl
Z2luUGF0aCgpOwogICAgY3R4Lm1vdmVUbygwLCAwKTsKICAgIGN0eC5saW5lVG8od2lkdGgsIGhl
aWdodCk7CiAgICBjdHguc3Ryb2tlKCk7CgogICAgLy8gZHJhdyBibGFjayBsaW5lCiAgICBjdHgu
c3Ryb2tlU3R5bGUgPSAiIzAwMCI7CiAgICBjdHguYmVnaW5QYXRoKCk7CiAgICBjdHgubW92ZVRv
KDAsIGhlaWdodC8yKTsKICAgIGN0eC5saW5lVG8od2lkdGgsIGhlaWdodC8yKTsKICAgIGN0eC5z
dHJva2UoKTsKICA8L3NjcmlwdD4KPC9ib2R5Pgo8L2h0bWw+
</data>

          </attachment>
      

    </bug>

</bugzilla>