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

IE 11 Problem with data URI images. #614

Closed
neurofuzzy opened this issue Feb 28, 2014 · 9 comments
Closed

IE 11 Problem with data URI images. #614

neurofuzzy opened this issue Feb 28, 2014 · 9 comments

Comments

@neurofuzzy
Copy link

I am loading some Sprites using PIXI.Sprite.fromImage and instead of using a URL, I'm using a data URI ("data:image/png;base64, ... ")

This works fine in all other browsers, but in IE it will sometimes not load the image. It's completely inconsistent. Sometimes all images load, but usually either none or some of them load. I imagine this is probably an event not being fired or a race condition.

Also, I've found that when doing this in IE, I need to use Texture.fromImage and assign it to a new Sprite. Weird.

It works normally about half the time in Canvas, and almost never in WebGL.

And one other thing to note - if I use a data URI I need to specify crossorigin as true or it throws an error. No biggie but a usability issue.

@neurofuzzy
Copy link
Author

I got this working consistently:

        var image = new Image();
        image.src = data_uri_string;
        var bt = new PIXI.BaseTexture(image);
        var texture = new PIXI.Texture(bt);
        var icon = new PIXI.Sprite(texture);
        image.onload = function ()
        {
            var bt = new PIXI.BaseTexture(image, PIXI.scaleModes.NEAREST);
            icon.texture = new PIXI.Texture(bt);
        };

It appears that SOMETIMES when an image is assigned a data URI, the image is not loaded instantly, and needs to be rebuilt. I see you have an onload handler in PIXI.BaseTexture, and I'm not sure why that's not working in this case.

@iirelu
Copy link
Contributor

iirelu commented Feb 28, 2014

I'm not even sure if IE is even supported by pixi.js, it's pretty incredible you even managed to get it running.

@drkibitz
Copy link
Contributor

I wonder if IE11 is sometimes reporting the wrong value for the img.complete property, a reduced test case would make that more clear.

@mattdesl
Copy link
Contributor

In a previous project, we noticed some strange issues with image.complete in IE. Sorry I can't reproduce this or provide any test cases at the moment. I ended up changing BaseTexture to not rely on image.complete at all, but instead always load images in the same consistent manner:

var image = new Image();

//attach listener before setting src
image.onload = ...func...

//setup the source
image.src = '...';

@ekelokorpi
Copy link
Contributor

I just tested Pixi on Windows 8.1 tablet, they use IE11.
Sometimes it doesn't show sprites at all, no matter if texture uses Data URI or normal URL.

It seems that sometimes even if img.complete is true, img.width and img.height are zero.

Adding width and height check to PIXI.BaseTexture solves the issue:

if((this.source.complete || this.source.getContext) && this.source.width && this.source.height)
{
    this.hasLoaded = true;
    this.width = this.source.width;
    this.height = this.source.height;

    PIXI.texturesToUpdate.push(this);
}
else
{

    var scope = this;
    this.source.onload = function() {

        scope.hasLoaded = true;
        scope.width = scope.source.width;
        scope.height = scope.source.height;

        // add it to somewhere...
        PIXI.texturesToUpdate.push(scope);
        scope.dispatchEvent( { type: 'loaded', content: scope } );
    };
}

Now all sprites are showing every time!

Would you accept PR?

@GoodBoyDigital
Copy link
Member

hells yeah! :)

On Tue, Apr 1, 2014 at 1:31 PM, Eemeli Kelokorpi
notifications@github.comwrote:

I just tested Pixi on Windows 8.1 tablet, they use IE11.
Sometimes it doesn't show sprites at all, no matter if texture uses Data
URI or normal URL.

It seems that sometimes even if img.complete is true, img.width and
img.height are zero.

Adding width and height check to PIXI.BaseTexture solves the issue:

if((this.source.complete || this.source.getContext) && this.source.width && this.source.height)
{
this.hasLoaded = true;
this.width = this.source.width;
this.height = this.source.height;

PIXI.texturesToUpdate.push(this);

}
else
{

var scope = this;
this.source.onload = function() {

    scope.hasLoaded = true;
    scope.width = scope.source.width;
    scope.height = scope.source.height;

    // add it to somewhere...
    PIXI.texturesToUpdate.push(scope);
    scope.dispatchEvent( { type: 'loaded', content: scope } );
};

}

Now all sprites are showing every time!

Would you accept PR?

Reply to this email directly or view it on GitHubhttps://github.com//issues/614#issuecomment-39199391
.

@GoodBoyDigital
Copy link
Member

Clsoing as this should be all good now in 1.5.3 👍 Thanks all!

@kanecko
Copy link

kanecko commented Dec 23, 2014

I still get this in IE9 and IE10 with Pixi 2.2.0.
http://codepen.io/anon/pen/ZYpQyj

It happens in PIXI.Sprite.prototype._renderCanvas at line

    else {
            renderSession.context.drawImage(
                                this.texture.baseTexture.source,
                                this.texture.crop.x,
                                this.texture.crop.y,
                                this.texture.crop.width,
                                this.texture.crop.height,
                                dx / resolution,
                                dy / resolution,
                                this.texture.crop.width / resolution,
                                this.texture.crop.height / resolution);

While in the codepen the tooltip text is initially set to an empty string, the error still happens when I set it to something non-empty.

@lock
Copy link

lock bot commented Feb 26, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Feb 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants