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

Error loading image for billboard: InvalidStateError: The source image could not be decoded. #7700

Closed
tangtony opened this issue Apr 1, 2019 · 6 comments

Comments

@hpinkos
Copy link
Contributor

hpinkos commented Apr 1, 2019

Thanks for reporting this @tangtony! We'll look into this and get it fixed for the next release

@hpinkos
Copy link
Contributor

hpinkos commented Apr 1, 2019

@OmarShehata are you the best one to take a look at this?

@OmarShehata
Copy link
Contributor

OmarShehata commented Apr 1, 2019

Yeah, I know why this is happening. It's because of the switch to using createImageBitmap:

#7579

You can confirm this by overriding the supports bitmap check to disable it at the top of your Sandcastle:

Cesium.Resource.supportsImageBitmapOptions = function(){
    return Cesium.when.resolve(false);
};

@OmarShehata
Copy link
Contributor

The good news is that data URIs in general should work fine with createImageBitmap. I think we need to handle SVG by wrapping it in an SVGImageElement before passing it to createImageBitmap.

@OmarShehata
Copy link
Contributor

We do intentionally fetch the given image as a blob before decoding it, since that allows the browser to move the expensive decode off the main thread. It looks like browsers don't support decoding vector data as a blob. From the spec:

If imageData is not in a supported image file format (e.g., it's not an image at all), or if imageData is corrupted in some fatal way such that the image dimensions cannot be obtained (e.g., a vector graphic with no intrinsic size), then reject p with an "InvalidStateError" DOMException and abort these steps.

Another workaround is to wrap the data URI in an image element before passing it in in your application:

var viewer = new Cesium.Viewer('cesiumContainer');

var img = document.createElement('img');
img.src = 'data:image/svg+xml,<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="100" height="100"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red"/></svg>';

viewer.entities.add({
    position : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
    billboard :{
        image : img
    }
});

I think the right fix is to essentially have Resource do this when it takes a vector image type. I wonder if we need to check for anything else other than just svg+xml ?

@lilleyse
Copy link
Contributor

lilleyse commented Apr 2, 2019

Fixed in #7701 and published a 1.56.1 release with the fix: https://github.com/AnalyticalGraphicsInc/cesium/releases/tag/1.56.1

@lilleyse lilleyse closed this as completed Apr 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants