Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Draft for fixing dimensionless SVG#13495

Draft
javagl wants to merge 1 commit into
mainfrom
fix-dimensionless-svg-DRAFT
Draft

Draft for fixing dimensionless SVG#13495
javagl wants to merge 1 commit into
mainfrom
fix-dimensionless-svg-DRAFT

Conversation

@javagl
Copy link
Copy Markdown
Contributor

@javagl javagl commented May 13, 2026

Not supposed to be merged!

Description

When an SVG does not contain width and height attributes, then it is rendered as black squares in Chrome 148, and prints a WebGL error in the console:

WebGL: INVALID_VALUE: texSubImage2D: bad image data
loadPartialImageSource	@	Texture.js:529

This can be reproduced with the image from issue 13479 and the following trivial sandcastle:

const viewer = new Cesium.Viewer("cesiumContainer");
viewer.entities.add({
  position: Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
  billboard: {
    image: "../images/icon1.svg",
  },
});

<!-- Include screenshots if appropriate -->

Sure, here's a screenshot of the rendered SVG:

Cesium SVG

🤡

This sill worked in Chrome 147. One could consider this to be a form of regression, but ... who would dare to blame Google here?

<!-- Describe your changes in detail -->

A general recommendation seems to be to not pass img elements to glTexSubImage2D, because it can cause all sorts of trouble and inconsistencies. Instead, one should draw the SVG into a canvas of the desired size, and use that canvas for the glTexSubImage2D instead.

The change here is a DRAFT that "works" with a local test. But it is by no means clear whether this is the right place for the change. The change is in the loadImageElement function, and for the record, I'll quote the full documentation of this function, its purpose, and its parameters here:


The code part itself and its call site link to...

to explain (or rather justify) what is done there, but 1. didn't backtrack through all these links (and some appear to be broken), and 2. any change will likely cause some form regression, given that there are several layers of workarounds stacked on top of each other.

For now, the purpose of this PR is only to illustrate that trying to load SVG directly appears to be prone to issues, and we should consider using the canvas-based approach instead.

Issue number and link

#13479

Testing plan

n/a

Author checklist

  • I have submitted a Contributor License Agreement
  • I have added my name to CONTRIBUTORS.md
  • I have updated CHANGES.md with a short summary of my change
  • I have added or updated unit tests to ensure consistent code coverage
  • I have updated the inline documentation, and included code examples where relevant
  • I have performed a self-review of my code

AI acknowledgment

  • I used AI to generate content in this PR
    • Yes
    • No
    • You decide: I typed "texSubImage2D svg img" into google, and some AI responded that one should usually not pass an SVG directly to this function, but draw it into a canvas instead. I could hardly prevent that.
  • If yes, I have reviewed the AI-generated content before submitting

If yes, I used the following Tools(s) and/or Service(s):

I think it's called "Gemini"...

If yes, I used the following Model(s):

Well...

@github-actions
Copy link
Copy Markdown
Contributor

Thank you for the pull request, @javagl!

✅ We can confirm we have a CLA on file for you.

Comment on lines +1941 to +1942
const ctx = canvas.getContext("2d");
ctx.drawImage(image, 0, 0);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Someone else will have to dig into whether this is actually a factor but at first glance I'd be cautious about reading back data from a canvas element given counter-fingerprinting protections like #12480

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some aspects that I haven't looked into - beyond the currently failing tests, and beyond the workarounds listed in the PR description.

During the first investigation pass, I was hoping that there could be a place where some
if (svg.width === undefined) svg.width = 42;
at the right place could trivially fix all this. But I didn't find an obvious place where this could be inserted.

It would be nice if this was an option, though. Every other solution could easily turn into some whack-a-mole situation, where every fix and/or the attempt to carefully roll back the existing workarounds could cause further regressions. The pointer to the fingerprinting may be an important one (even though I don't know exactly where this will kick in). But I'd see this as another reason why it could be nice to try and fix this "in the source data", by inserting some default size...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants