vassalengine / vassal

VASSAL, the open-source boardgame engine
https://vassalengine.org
GNU Lesser General Public License v2.1
435 stars 105 forks source link

Batik chokes on SVG without explicit xlink namespace #12305

Open djberg96 opened 1 year ago

djberg96 commented 1 year ago

It seems that the xlink namespace is deprecated: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/xlink:href, and major browsers do not require it, so I omitted it from my personal SVG files. However, if you try to add an SVG file without it (say, to a pieces scrollable list), the Vassal UI will silently fail. Only the log file tells you the problem:

2023-05-14 23:07:58,354 [18359-pool-1-thread-2] ERROR VASSAL.tools.image.svg.SVGRenderer - 
org.apache.batik.transcoder.TranscoderException: null
Enclosed Exception:
jar:file:/Users/dberger/Downloads/Vassal/Modules/TestModule.vmod!/images/clinton_british_infantry.svg:-1
The attribute "xlink:href" of the element <use> is required
    at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:228)
    at VASSAL.tools.image.svg.SVGRenderer$Rasterizer.transcode(SVGRenderer.java:222)
    at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:142)
    at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:158)
    at VASSAL.tools.image.svg.SVGRenderer.render(SVGRenderer.java:129)
    at VASSAL.tools.imageop.RotateScaleOpSVGImpl.eval(RotateScaleOpSVGImpl.java:121)
    at VASSAL.tools.imageop.RotateScaleOpSVGImpl.eval(RotateScaleOpSVGImpl.java:51)
    at VASSAL.tools.opcache.OpCache$Request.doInBackground(OpCache.java:203)
    at java.desktop/javax.swing.SwingWorker$1.call(SwingWorker.java:304)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
    at java.desktop/javax.swing.SwingWorker.run(SwingWorker.java:343)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: org.apache.batik.bridge.BridgeException: jar:file:/Users/dberger/Downloads/Vassal/Modules/TestModule.vmod!/images/clinton_british_infantry.svg:-1
The attribute "xlink:href" of the element <use> is required
    at org.apache.batik.bridge.SVGUseElementBridge.buildCompositeGraphicsNode(SVGUseElementBridge.java:120)
    at org.apache.batik.bridge.SVGUseElementBridge.createGraphicsNode(SVGUseElementBridge.java:98)
    at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:213)
    at org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:171)
    at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:219)
    at org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:171)
    at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:219)
    at org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:171)
    at org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:82)
    at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:210)
    ... 13 common frames omitted

Instead of silently failing, I feel it would be better to see a popup error of some sort, e.g. in this case something that just says "The attribute "xlink:href" of the element is required"

uckelman commented 1 year ago

What you're seeing is that Batik lacks SVG 2 support at present.

djberg96 commented 1 year ago

Understood, but can we change the UI from silently failing to a popup erorr of some kind?

uckelman commented 1 year ago

I'll review it if somebody makes a PR for it.