Bug 46618 - NPE when changing an element during animation
Summary: NPE when changing an element during animation
Status: NEW
Alias: None
Product: Batik - Now in Jira
Classification: Unclassified
Component: Animation engine (show other bugs)
Version: 1.8
Hardware: PC Windows Server 2003
: P2 major
Target Milestone: ---
Assignee: Batik Developer's Mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-28 06:35 UTC by Age Bosma
Modified: 2009-02-02 03:08 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Age Bosma 2009-01-28 06:35:10 UTC
JDK: 1.6.0_07
Batik: batik-src-09-01-04.zip

When you have an animated element and you change e.g. the border colour you get a NullPointerException.

SVG file cut:

<rect x="20" y="20" width="100" height="100" style="stroke:#ffffff;stroke-width:1;" fill="blue" id="hlRect">
    <animate attributeType="CSS" attributeName="opacity" from="1" to="0" begin="0s;blue_fade_in.end" dur="1s" id="blue_fade_out"/>
    <animate attributeType="CSS" attributeName="opacity" from="0" to="1" begin="blue_fade_out.end" dur="1s" id="blue_fade_in"/>
</rect>


In this case it's a simple rect but the same will happen when you animate a group which contains elements on which you perform the action.
When you start the application the animation will run as expected. As soon as you change e.g. the stroke colour with Java you'll get a NPE.

Java code cut:

svgCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable() {
    public void run() {
        SVGDocument svgDoc = svgCanvas.getSVGDocument();
        Element hlElement = svgDoc.getElementById("hlRect");
        ((org.w3c.dom.svg.SVGStylable)hlElement).getStyle().setProperty("stroke", "deepskyblue", "");
    }
});


NPE:

java.lang.NullPointerException
  at org.apache.batik.anim.timing.TimedElement.addInstanceTime(Unknown Source)
  at org.apache.batik.anim.timing.SyncbaseTimingSpecifier.newInterval(Unknown Source)
  at org.apache.batik.anim.timing.TimedElement.notifyNewInterval(Unknown Source)
  at org.apache.batik.anim.timing.TimedElement.selectNewInterval(Unknown Source)
  at org.apache.batik.anim.timing.TimedElement.sampleAt(Unknown Source)
  at org.apache.batik.anim.timing.TimedDocumentRoot.seekTo(Unknown Source)
  at org.apache.batik.anim.AnimationEngine.tick(Unknown Source)
  at org.apache.batik.bridge.SVGAnimationEngine.access$600(Unknown Source)
  at org.apache.batik.bridge.SVGAnimationEngine$AnimationTickRunnable.run(Unknown Source)
  at org.apache.batik.util.RunnableQueue.run(Unknown Source)
  at java.lang.Thread.run(Thread.java:619)


This NPE will be displayed repeatedly.
Let me know if you need any more info.
Comment 1 Age Bosma 2009-02-02 03:08:41 UTC
With the latest nightly (batik-src-09-01-28.zip) I get the same result.

After some additional testing I came to the conclusion that I included the wrong svg code in the bug report. The issue is caused because of the use of the 'use' element when placed in a 'g' element, referencing the group in the 'use' element.

Revised code:
<g id="hlGroup">
<rect x="20" y="20" width="100" height="100"
style="stroke:#ffffff;stroke-width:1;" fill="blue" id="hlRect">
    <animate attributeType="CSS" attributeName="opacity" from="1" to="0"
begin="0s;blue_fade_in.end" dur="1s" id="blue_fade_out"/>
    <animate attributeType="CSS" attributeName="opacity" from="0" to="1"
begin="blue_fade_out.end" dur="1s" id="blue_fade_in"/>
</rect>
</g>
<use xlink:href="#hlGroup" transform="translate(0,120)" />

Placing the group in the a 'defs' element makes no difference.

When you refence the 'rect' element in the 'use' element directly instead of the group, the error does not occur. Though this might just as well be because of, what appears to be, a different bug. When changing the e.g. the stroke colour when refencing the 'rect' element directly, the stroke colour of the 'use' element will not change in the first place.