Skip to content

Commit

Permalink
Improve AssetLibrary.loadText, include additional error information i…
Browse files Browse the repository at this point in the history
…f asset does not load
  • Loading branch information
jgranick committed Mar 16, 2017
1 parent 47acb62 commit 4afc34e
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions lime/utils/AssetLibrary.hx
Expand Up @@ -7,6 +7,7 @@ import lime.app.Future;
import lime.app.Promise;
import lime.media.AudioBuffer;
import lime.graphics.Image;
import lime.net.HTTPRequest;
import lime.text.Font;
import lime.utils.AssetType;

Expand Down Expand Up @@ -635,27 +636,26 @@ class AssetLibrary {

return Future.withValue (cachedText.get (id));

} else {
} else if (cachedBytes.exists (id) || classTypes.exists (id)) {

var bytes = getBytes (id);

return loadBytes (id).then (function (bytes) {
if (bytes == null) {

return new Future<String> (function () {

if (bytes == null) {

return null;

} else {

var text = bytes.getString (0, bytes.length);
cachedText.set(id, text);
return text;

}

}, true);

This comment has been minimized.

Copy link
@vizanto

vizanto Mar 20, 2017

Contributor

Depends how you look at it:

Before this patch, Assets.loadText would not use the cache but call AssetLibrary.loadText which cached it anyway.

Now, cachedText is not updated anywhere, except for this.load through loadText_onComplete.

Should caching of TEXT and BINARY be added to lime.utils.Assets.loadText?

return cast Future.withValue (null);

} else {

});
var text = bytes.getString (0, bytes.length);
cachedText.set (id, text);
return Future.withValue (text);

}

} else {

var request = new HTTPRequest<String> ();
return request.load (paths.get (id));

This comment has been minimized.

Copy link
@vizanto

vizanto Mar 20, 2017

Contributor

Shouldn't this also add to cache on load completion?
I'm now getting:

ERROR: TEXT asset "..." exists, but only asynchronously

Above error is introduced after OpenFL 4.7.1

This comment has been minimized.

Copy link
@vizanto

vizanto Mar 20, 2017

Contributor

Woops, I now see caching handled in loadText_onComplete
Error is caused somewhere else. Or not... (see line 656)


}

Expand Down Expand Up @@ -859,7 +859,16 @@ class AssetLibrary {

private function load_onError (id:String, message:Dynamic):Void {

promise.error ("Error loading asset \"" + id + "\"");
if (message != null && message != "") {

promise.error ("Error loading asset \"" + id + "\": " + Std.string (message));

} else {

promise.error ("Error loading asset \"" + id + "\"");

}


}

Expand Down

0 comments on commit 4afc34e

Please sign in to comment.