Uploaded image for project: 'Batik'
  1. Batik
  2. BATIK-862

AnimationEngine.removeAnimation doesn't clean up the "animation sandwich" correctly.

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Resolution: Fixed
    • Affects Version/s: 1.7
    • Fix Version/s: None
    • Component/s: SVG Viewer
    • Labels:
      None
    • Environment:
      Operating System: Windows XP
      Platform: PC

      Description

      When a user tries to remove an animation node, the removeAnimation function fails to remove the associated "animation sandwich" object that left in the TargetInfo.otherAnimations internal storage. The sandwich is referring to a 'null' animation which cause null pointer exception when the viewer tries to execute all animations against the target element.

      ========= Here is the exception ===========
      java.lang.NullPointerException
      at org.apache.batik.anim.AnimationEngine.tick(AnimationEngine.java:389)
      at org.apache.batik.bridge.SVGAnimationEngine.access$601(SVGAnimationEngine.java:99)
      at org.apache.batik.bridge.SVGAnimationEngine$AnimationTickRunnable.run(SVGAnimationEngine.java:859)
      at org.apache.batik.util.RunnableQueue.run(RunnableQueue.java:237)
      at java.lang.Thread.run(Unknown Source)

      ========== Here is a test case ============
      var activeElement = svgDoc.getElementById("theElement");
      var anim = svgDoc.createElementNS("http://www.w3.org/2000/svg", "animateMotion");
      anim.setAttributeNS(null, "id", "1");
      anim.setAttributeNS(null, "dur", "1");
      anim.setAttributeNS(null, "path", "m 0, 0 L 0, 5");
      anim.setAttributeNS(null, "begin", "indefinite");
      anim.setAttributeNS(null, "fill", "freeze");
      activeElement.appendChild(anim);

      var anim2 = svgDoc.createElementNS("http://www.w3.org/2000/svg", "animate");
      anim2.setAttributeNS(null, "id", "2");
      anim2.setAttributeNS(null, "dur", "1");
      anim2.setAttributeNS(null, "values", "0;26;51;76;102");
      anim2.setAttributeNS(null, "attributeName", "x");
      anim2.setAttributeNS(null, "begin", "indefinite");
      anim2.setAttributeNS(null, "fill", "freeze");
      activeElement.appendChild(anim2);

      activeElement.removeChild(anim);

      anim2.beginElement();

      =========== here is the purposed solution ==============
      protected Sandwich removeSandwich(AnimationTarget target, short type,
      String ns, String an) {
      TargetInfo info = getTargetInfo(target);
      Sandwich sandwich;
      if (type == ANIM_TYPE_XML)

      { sandwich = (Sandwich) info.xmlAnimations.remove(ns, an); }

      else if (type == ANIM_TYPE_CSS)

      { sandwich = (Sandwich) info.cssAnimations.remove(an); }

      else

      { sandwich = (Sandwich) info.otherAnimations.remove(an); }

      return sandwich;
      }

      public void removeAnimation(AbstractAnimation anim) {
      timedDocumentRoot.removeChild(anim.getTimedElement());
      AbstractAnimation nextHigher = anim.higherAnimation;
      if (nextHigher != null)

      { nextHigher.markDirty(); }

      moveToBottom(anim);
      if (anim.higherAnimation != null)

      { anim.higherAnimation.lowerAnimation = null; }

      AnimationInfo animInfo = getAnimationInfo(anim);
      Sandwich sandwich = getSandwich(animInfo.target, animInfo.type,
      animInfo.attributeNamespaceURI,
      animInfo.attributeLocalName);
      if (sandwich.animation == anim)

      { sandwich.animation = null; sandwich.lowestAnimation = null; sandwich.shouldUpdate = true; removeSandwich(animInfo.target, animInfo.type, animInfo.attributeNamespaceURI, animInfo.attributeLocalName); }

      }

        Attachments

        1. Bug46124-Patch.patch
          1 kB
          Helder Magalhães
        2. Bug46124-Testcase.svg
          2 kB
          Helder Magalhães

          Issue Links

            Activity

              People

              • Assignee:
                batik-dev@xmlgraphics.apache.org Batik Developer's Mailing list
                Reporter:
                schui@tririga.com Steve Chui
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: