haxeui / haxeui-openfl

The OpenFL backend of the HaxeUI framework -
http://haxeui.org
MIT License
42 stars 14 forks source link

WEBP image errors on Windows #62

Open SKBotNL opened 1 year ago

SKBotNL commented 1 year ago

Expected Behavior

The resource should load

Current Behavior

When using an external image/web address as the resource of an image the built program for Windows errors with:\ haxe/ui/backend/AssetsImpl.hx:95: [IOErrorEvent type="ioError" bubbles=true cancelable=false text="Unknown error" errorID=0]

Steps to Reproduce (for bugs)

  1. Create an Image
  2. Build the project for Windows
  3. See error

Test app / minimal test case

package;

import haxe.ui.containers.VBox;
import haxe.ui.components.Image;
import haxe.ui.HaxeUIApp;

class Main {
    public static function main() {
        var app = new HaxeUIApp();
        app.ready(function() {
            var vbox = new VBox();
            vbox.percentHeight = 100;
            vbox.percentWidth = 100;

            var image = new Image();
            image.resource = "https://cdn.discordapp.com/icons/613425648685547541/a_08b73e86d3c5661db3e397e4c557f751.webp";
            image.width = 128;
            image.height = 128;

            vbox.addComponent(image);
            app.addComponent(vbox);
            app.start();
        });
    }
}

Your Environment

ianharrigan commented 1 year ago

Does it happen with, for example, png images?

SKBotNL commented 1 year ago

Does it happen with, for example, png images?

PNGs don't seem to even load.

ianharrigan commented 1 year ago

hmmm, that seems odd - i wonder if something has changed internally in lime or hxcpp or something... bear with me, ill try this end (i would have expected webp to not work, unless that is supported by openfl / lime?)

ianharrigan commented 1 year ago

OK, so can repro with the webp, which i think is probably valid because im guessing it doesnt support webp... although the error seems a little odd... (ill look into it).

I cant repro with a png, i tried: https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png and it seemed fine... what url were you using?

Cheers, Ian

SKBotNL commented 1 year ago

https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png

That png indeed works, others such as https://via.placeholder.com/600x400.png and https://filesamples.com/samples/image/png/sample_1280%C3%97853.png don't work

ianharrigan commented 1 year ago

image

Seems fine this end... ill update all my libs, something must have changed? What versions of openfl, lime, haxe, etc are you running?

SKBotNL commented 1 year ago

image

Seems fine this end... ill update all my libs, something must have changed? What versions of openfl, lime, haxe, etc are you running?

Can you share your code? Versions:

SKBotNL commented 1 year ago

Actually, after some more testing, it seems that in this case html5 is actually having an issue

ianharrigan commented 1 year ago

right, that also makes sense i think the browser is preventing haxe (not haxeui) from making that http request becuase the requested resources has said (CORS):

Access to XMLHttpRequest at 'https://filesamples.com/samples/image/png/sample_1280%C3%97853.png' from origin 'http://127.0.0.1:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Access to XMLHttpRequest at 'https://via.placeholder.com/600x400.png' from origin 'http://127.0.0.1:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

It may work if you deployed to a real domain rather than localhost (but probably not)

SKBotNL commented 1 year ago

right, that also makes sense i think the browser is preventing haxe (not haxeui) from making that http request becuase the requested resources has said (CORS):

Access to XMLHttpRequest at 'https://filesamples.com/samples/image/png/sample_1280%C3%97853.png' from origin 'http://127.0.0.1:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Access to XMLHttpRequest at 'https://via.placeholder.com/600x400.png' from origin 'http://127.0.0.1:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

It may work if you deployed to a real domain rather than localhost (but probably not)

That makes sense, is there any way to add a Access-Control-Allow-Origin header to the request?

ianharrigan commented 1 year ago

well, Access-Control-Allow-Origin comes from the server, not the browser, so the short answer is nope, it aint gonna happen. Maybe the http server you actually want to get images for is under your control? In which case you should be fine.

SKBotNL commented 1 year ago

well, Access-Control-Allow-Origin comes from the server, not the browser, so the short answer is nope, it aint gonna happen. Maybe the http server you actually want to get images for is under your control? In which case you should be fine.

You're right. Lucky that is indeed the case.

SKBotNL commented 1 year ago

OpenFL's Loader does not seem to support WEBP, as you can see from this switch: https://github.com/openfl/openfl/blob/develop/src/openfl/display/Loader.hx#L434. Should we create an issue in openfl/openfl?