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
hitContext.getImageData causing crash #2313
Comments
Problem was resolve by adding: in the create: function() {} of my first state, in this case "Boot.js" as per the Phaser Game template. |
This is a local configuration issue, rather than a Phaser one. If you've tainted the canvas somehow (or in this case the image it's trying to read from) then this error will occur. There's nothing Phaser itself can do about it, you just have to correctly handle CORs loading of the assets in the first place. |
I already stated the local configuration isn't the issue at all here. Even the comments in the phaser.js also point out that crossOrigin param on the Loader object needs to be changed. I've got'n this same response everywhere its a CORs issue... and it isn't. It only happens on hitcontext but whatever it was resolved but updating and any following devs can see this answer instead of having to argue on every form to fight through this issue. This was brought up in : By you photonstorm. |
#1684 is unrelated to this. That is about the base object not actually having a texture that can be pixel checked (i.e. a BitmapText object) that maps to what is displayed on-screen, hence why it was flagged as a feature request and not an issue. Your issue however is 100% CORs related I'm afraid. From MDN: What is a "tainted" canvas? "Although you can use images without CORS approval in your canvas, doing so taints the canvas. Once a canvas has been tainted, you can no longer pull data back out of the canvas. For example, you can no longer use the canvas toBlob(), toDataURL(), or getImageData() methods; doing so will throw a security error. This protects users from having private data exposed by using images to pull information from remote web sites without permission." Which is exactly what happens here. The canvas is tainted because the image wasn't CORs loaded, and doing a pixel perfect hit test uses There are ways around it, sites like https://crossorigin.me/ exist for example, or if you have control over the origin server then setting the correct response headers works too. Either way it's local to your server set-up and is nothing Phaser can check for. |
Setting input.pixelPerfectOver=true on a Phaser.Sprite object causes the following error :
Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.
First yes my Access-Control-Allow-Origin "*" is set properly.
Secondly if I turn pixelPerfectOver=false I have no problems with the displaying and interacting through input/events on the Phaser.Sprite.
Example Source:
The text was updated successfully, but these errors were encountered: