Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Blocker Blocker
    • Resolution: Unresolved
    • Affects Version/s: current
    • Fix Version/s: milestone 1
    • Component/s: implementation
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      96

      Description

      There is an error in GraphicsJAI when one attempts to create a GraphicsJAI from
      an existing Graphics2D. If the GraphicsJAI goes out of scope it can ruin the
      original Graphics2D and causes some method invokations, such as to g2d.fill
      (shape), to be ignored in JRE1.6 (and throw NullPointerExceptions in JRE1.5).

      Consider code that uses a Graphics2D but creates a GraphicsJAI in a separate
      block, as follows:

      ---------------------------------------------------------
      ....
      if (getImage() != null)
      {
      AffineTransform scale = new AffineTransform();
      scale.setToScale(getZoom(), getZoom());
      GraphicsJAI gjai = GraphicsJAI.createGraphicsJAI(g2d, this);
      gjai.drawRenderedImage(image, scale);
      }
      .....
      g2d.fill(shape); //fails to render

      ------------------------------------------------------------

      In JRE1.5 it randomly throws and exception, and in JRE1.6 it never throws and
      exception, but it silently fails to render the shape. I made the following
      change and magically it works:

      ---------------------------------------------------------
      ....
      GraphicsJAI gjai = GraphicsJAI.createGraphicsJAI(g2d, this);
      if (getImage() != null)
      {
      AffineTransform scale = new AffineTransform();
      scale.setToScale(getZoom(), getZoom());
      gjai.drawRenderedImage(image, scale);
      }
      .....
      gjai.fill(shape); //works!

      ------------------------------------------------------------

      Looking at the sourcecode, I can see an apparent bug in the GraphicsJAI.java
      file. The 'dispose' method calls 'dispose' on the inner Graphics2D. Since my
      gjai variable above has gone out of scope, it could be finalized at any time.
      Presumably this could call 'dispose' on gjai, which would also dispose my g2d
      object. Since my g2d object is still in scope, the gjai object robs it of its
      resources and causes it to attempt to render onto a null surface.

      I think the proper behavior would be to override 'Finalize' so that it does not
      call dispose – the finalize method of the inner Graphics2D can take care of
      that!

      John

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            jai-core-issues
            Reporter:
            johncfemiani
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: