benfry / processing4

Processing 4.x releases for Java 17
https://processing.org
Other
1.34k stars 240 forks source link

Loading SVG file gives `Illegal base64 character 20` encoding error (worked in v3.5.4) #592

Closed villares closed 1 year ago

villares commented 1 year ago

Description

SVG files that could previously be loaded and displayed in Processin 3.5.4 no longer work.

Expected Behavior

image

Current Behavior

Sketch is interrupted with Illegal base64 character 20 error.

Steps to Reproduce

  1. Copy this SVG file to a data folder inside a new sketch: https://github.com/villares/desenho-sem-argumentos/blob/2022/1_outubro_2022/gerador_completo/base_frente.svg
  2. Paste in and run this code:
    void setup(){
    size(562, 920);
    PShape frente = loadShape("base_frente.svg");
    shape(frente, 0, 0, 562, 920);  // optional, will not be reached
    }

Your Environment

More information

Accessing Processing 4 core from py5 I got this:

Filters are not supported.
Ignoring <clipPath> tag.
py5 encountered an error in your code:File "PSurfaceNone.java", line 356, in processing.core.PSurfaceNone$AnimationThread.run

File "PSurfaceAWT.java", line 1386, in processing.awt.PSurfaceAWT$9.callDraw

File "PApplet.java", line 2088, in processing.core.PApplet.handleDraw

File "Sketch.java", line 196, in py5.core.Sketch.setup

File "jdk.proxy2.$Proxy7.java", line -1, in jdk.proxy2.$Proxy7.run_method

File "org.jpype.proxy.JPypeProxy.java", line -1, in org.jpype.proxy.JPypeProxy.invoke

File "org.jpype.proxy.JPypeProxy.java", line -2, in org.jpype.proxy.JPypeProxy.hostInvoke

File "PApplet.java", line 12377, in processing.core.PApplet.shape

File "PGraphics.java", line 4220, in processing.core.PGraphics.shape

File "PShape.java", line 1654, in processing.core.PShape.draw

File "PShape.java", line 1665, in processing.core.PShape.drawImpl

File "PShape.java", line 1680, in processing.core.PShape.drawGroup

File "PShape.java", line 1654, in processing.core.PShape.draw

File "PShape.java", line 1665, in processing.core.PShape.drawImpl

File "PShape.java", line 1680, in processing.core.PShape.drawGroup

File "PShape.java", line 1654, in processing.core.PShape.draw

File "PShape.java", line 1667, in processing.core.PShape.drawImpl

File "PShape.java", line 1712, in processing.core.PShape.drawPrimitive

File "PShape.java", line 1951, in processing.core.PShape.loadImage

File "PShape.java", line 1971, in processing.core.PShape.loadBase64Image

File "PShape.java", line 1988, in processing.core.PShape.parseBase64Image

File "Base64.java", line 589, in java.util.Base64$Decoder.decode

File "Base64.java", line 566, in java.util.Base64$Decoder.decode

File "Base64.java", line 847, in java.util.Base64$Decoder.decode0

Exception: Java Exception

The above exception was the direct cause of the following exception:

File "/home/villares/GitHub/desenho-sem-argumentos/1_outubro_2022/gerador_completo/gerador_completo_wip.py", line 10, in _py5_faux_setup
    6    def setup():
    7        size(562, 943)
    8        
    9        frente = load_shape('data/base_frente.svg')
--> 10       shape(frente, 0, 0, 562, 943)
    ..................................................
     frente = <py5.shape.Py5Shape object at 0x7fadf5a4fc40>
    ..................................................

java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Illegal base64 character 20
jaegonlee commented 1 year ago

The file contains 'white space character(0x20)' and it causes error. It is skipped in Processing 3(javax.xml.bind.DatatypeConverter), but not in Processing 4(java.util.Base64). Delete white spaces may fix it. (line 1987 in PShape.java)

svg

hx2A commented 1 year ago

@jaegonlee , thank you for finding a solution to this bug. It looks like you tested this and found the solution does solve the problem. What are the next steps? Will you submit a PR for this?

vepo commented 1 year ago

It looks like this image has an error. I was searching for this error and it can be solved by replacing byte[] decodedBytes = Base64.getDecoder().decode(encodedData); with byte[] decodedBytes = Base64.getUrlDecoder().decode(encodedData);. I did this change by we still have an error.

I will try to create a more stable code, first trying to using the default decoder, than the UrlDecoder and if it does not work I will replace all invalid values before using the default encoder again.

You can find more information here: https://www.prostdev.com/post/understanding-the-illegal-base64-character-error-java-groovy-and-mule-4-dw-2-0

benfry commented 1 year ago

Awesome, thanks again @jaegonlee and @vepo. Fix is incorporated for 4.0.2.

github-actions[bot] commented 1 year ago

This issue has been automatically locked. To avoid confusion with reports that have already been resolved, closed issues are automatically locked 30 days after the last comment. Please open a new issue for related bugs.