Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
villares opened this issue Nov 7, 2022 · 5 comments
Labels
Help Wanted We have very little time and would like some help

Comments

@villares
Copy link
Contributor

villares commented Nov 7, 2022

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

  • Processing version: Processing 4.0.1
  • Operating System and OS version: Manjaro 21.3 Kernel 5.15

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
@villares villares changed the title Loading SVG file that worked in Processing 3.5.4 now gives Illegal base64 character 20 encoding error Loading SVG file gives Illegal base64 character 20 encoding error (worked in v3.5.4) Nov 7, 2022
@benfry benfry added the Help Wanted We have very little time and would like some help label Nov 11, 2022
@jaegonlee
Copy link

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
Copy link
Contributor

hx2A commented Nov 13, 2022

@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
Copy link
Contributor

vepo commented Nov 13, 2022

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

@vepo vepo mentioned this issue Nov 13, 2022
@benfry benfry closed this as completed in f52b900 Nov 24, 2022
benfry added a commit that referenced this issue Nov 24, 2022
@benfry
Copy link
Owner

benfry commented Nov 24, 2022

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

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Help Wanted We have very little time and would like some help
Projects
None yet
Development

No branches or pull requests

5 participants