Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8093604

LinearGradient with too many stops can cause failure later during Scene background fill

    Details

      Description

      When creating a LinearGradient with 14 stops I get this:

      java.lang.RuntimeException: Maximum number of gradient stops exceeded (paint uses 14 stops, but max is 12)
      at com.sun.prism.impl.ps.PaintHelper.stopsToImage(PaintHelper.java:168)
      at com.sun.prism.impl.ps.PaintHelper.initGradient(PaintHelper.java:260)
      at com.sun.prism.impl.ps.PaintHelper.setMultiGradient(PaintHelper.java:292)
      at com.sun.prism.impl.ps.PaintHelper.setLinearGradient(PaintHelper.java:432)
      at com.sun.prism.impl.ps.BaseShaderContext.updatePaintShader(BaseShaderContext.java:250)
      at com.sun.prism.impl.ps.BaseShaderContext.validatePaintOp(BaseShaderContext.java:490)
      at com.sun.prism.impl.ps.BaseShaderContext.validatePaintOp(BaseShaderContext.java:418)
      at com.sun.prism.impl.ps.BaseShaderContext.validatePaintOp(BaseShaderContext.java:351)
      at com.sun.prism.impl.BaseContext.validateClearOp(BaseContext.java:116)
      at com.sun.prism.es2.ES2Graphics.clear(ES2Graphics.java:78)
      at com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPainter.java:462)
      at com.sun.javafx.tk.quantum.ViewPainter.paintImpl(ViewPainter.java:320)
      at com.sun.javafx.tk.quantum.UploadingPainter.run(UploadingPainter.java:135)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
      at com.sun.javafx.tk.RenderJob.run(RenderJob.java:58)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
      at java.lang.Thread.run(Thread.java:745)


      There are several problems with this limitation.

      1) It is not documented in LinearGradient. It should.
      2) It isn't enforced until drawn the first time. It should be enforced when LinearGradient is created if it's a hard limit.
      3) It is arbitrary and illogical.

      The golden rule of limitations is: 0, 1 or until memory runs out.

      This limitation is especially troublesome for environments where the LinearGradient is created dynamically with user input. Limiting the stops to 12 will affect the functionality of the application in a way that isn't apparent to the end user and definitely not logical.

      Also, it is not good practice to have check for hard limits like this since it requires constant checks if it has been lifted and then versioned to not be in apps targeting JDK's after that.

        Attachments

          Activity

            People

            • Assignee:
              flar Jim Graham
              Reporter:
              mgrev Mikael Grev
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: