Assets.getImage fails when run in Application.new

I created a new lime project with lime create HelloWorld. I then added var img = Assets.getImage("path/to/image.png"); in the new method. When I run lime test html5, it just blocks forever and never gets to the render function. When I run lime test mac, it throws an error: Error : Failure type not string @ ./Sys.cpp:404. This seems to only be a problem if run in the new method.

The Lime “new” constructor occurs before the preload has happened, which means that the Assets class is not available yet. You can use it later after update and render have started firing, would be happy to hear feedback on ways you think the API in general could be improved, though

(This is different than OpenFL, which starts at a higher level, where you already have a window and renderer running)

Understood, thanks! I tried the init function but had the same problem. I suppose I could just put my loading code in the render function by putting it inside a conditional that checks if img is null, but I was trying to avoid that. Would it be possible to add an assertion in the code, so you get a clearer error message? That would be my only suggestion. I will probably try using OpenFL itself, but I wanted to try using Lime directly first.

I believe that init() was changed to be called sooner, so it does not call after Assets has been initialized. On native platforms, we could initialize Assets much sooner, but on HTML5 and Flash, you need to preload before Assets will work. I had to patch one of the samples to check for a null image in the render method, but I agree, I would like to think of a nicer way to handle this (while still providing robust flexibility for controlling the application life cycle)