snowkit / snow

A low level cross platform framework for Haxe. Mac, Windows, Linux, Android, iOS, WebGL.
http://snowkit.org/snow
MIT License
133 stars 35 forks source link

web; load an image from an url throws error #84

Closed smvilar closed 8 years ago

smvilar commented 9 years ago

I'm trying to use this sample from awesome-snowkit to load an image from the url and display it in a luxe texture.

I made this repo with the actual test: https://github.com/smvilar/luxe-image-from-url

The console displays this error when calling Luxe.snow.assets.image_from_bytes

error(failed to load image from bytes, on error: [object Event])
smvilar commented 8 years ago

@underscorediscovery have you seen this issue? I wanna know if I'm doing something wrong here.

ruby0x1 commented 8 years ago

I have seen this but I've been busy in the backend, but I had a quick look so long.

Here's what I mean, this is a working png file (default font): screen 2015-11-30 at 6 12 34 pm

And here is your data: screen 2015-11-30 at 6 12 53 pm

What you see here is actually a , a replacement character. When encoded as UTF-8, this character (0xFFFD) becomes � (0xEF 0xBF 0xBD).

When I see that - I know that somewhere, the data has been converted to UTF-8 encoding, when it shouldn't be. This means that it will mess with the raw PNG data, making the image data invalid.

In simpler words: The error comes from the conversions, before getting to the image_from_bytes call.

Internally snow uses js.html.XMLHttpRequest() directly,

The reason I did it this way internally was because of similar encoding problems, where it must remain binary data in order to be used correctly.

Hope that helps so long.

smvilar commented 8 years ago

Thanks! I updated the example to use js.html.XMLHttpRequest directly with the parameters you set and it worked.

I should warn @bmfs to update his gist

anissen commented 8 years ago

I should warn @bmfs to update his gist

@smvilar Good idea. If you cannot reach him, you can fork his gist and correct it and then ping me and I'll point the link to the corrected gist instead.

bmfs commented 8 years ago

just updated the gist to use Luxe.snow.io.data_load(url).

Thanks for the warning

ruby0x1 commented 8 years ago

:+1: