Is it possible to hide "Failed to find image" warning log?

My app tries to call display.newImage() and if the file does not exist, there is a warning like this in the console log:

Warning: /Users/me/Documents/project/main.lua:98: Failed to find image 'tmpImage7155422274\_10153014678042275.png'

There are just too many warnings of this kind for this app. Is it possible to hide this warning log generated by Corona?

I think a more pertinent question is: why is your app is trying to load so many images that don’t exist?

For example, a news app that will download images dynamically during run time.

The app tries to display a image directly from a temp folder in case it has been downloaded earlier. 

Therefore, if it has not been downloaded before, this warning message is shown.

Well, I can’t help you hide the message, but I can help you avoid it.

At a small cost, you can first check to see if the image exists before you try to use it.

  1. Add this to your main.lua or early in the init/load process.

    function io.exists( fileName, base ) local base = base or system.DocumentsDirectory local fileName = fileName if( base ) then fileName = system.pathForFile( fileName, base ) end if not fileName then return false end local f=io.open(fileName,“r”) if (f == nil) then return false end io.close(f) return true end

  2. use it like this:

    if( io.exists( <path to file here> , system.TemporaryDirectory ) ) then – load from ‘disk’ else – download the image first end

I’ve also run into this with an app that has some images bundled into the build but can also download updated images when the app is running.

On Android, some files get packaged in the build in a manner that prevents you from checking if they exist. See section 5 of this blog post: http://coronalabs.com/blog/2013/02/13/faq-wednesday-sub-folder-and-file-access/

I experimented with several different solutions, including the one suggested in blog of naming the file picture1.png.txt and then doing a copy and rename. In the end, the cleanest most reliable solution for me was to just do a call to display.newImage and then check if the result is null. This produces those annoying warnings but they’re not visible to the average app user.

thanks, roaminggamer

I thought about checking if the file exists first like you suggested. The problem is about the “small cost”. I don’t want to make the io check because it might affect the performance a bit just for turning off the warning log.

However, after a second thought, I should use this io check only for “Simulator” so I won’t see the annoying warning again for my own testing and that’s good enough.

You’re right about that cost.  I have to pay it for an app I’m currently actively developing, but if I could avoid it I would.  

Excellent choice, to only do it on the simulator though.  I too hate excessive error messages while debugging in the simulator.

I doubt the overhead for checking is much more than trying to load the image and having it fail.

Rob

@Rob,

You’re right.  Loading the file as a test and loading the file to build the image should be about the same (or even less).

However if you check for existence every time, you pay for two loads every time. i.e. Load to test + Load to display.

On the other hand if you use failed creations as a test, you pay a near-zero cost for failed loads which should result in a remote request.

Thus you pay one load per load plus a small failed create cost followed by the long download time on missing image cases.

PS - I’m not sure if there is any hidden caching going on for a previosly loaded file (via io), but I assume there isn’t.

I have learned i/o operations (saving to/loading from disk) would cause significant impact on graphic animations, especially for Android devices.

For the case that an image exists, extra i/o check is done just for turning off the log, which is something I don’t want to do.

I think this warning message was not there earlier, it was added probably in recent few months. Not sure about the intention, maybe to remind the developer what filename & path are missing? But for apps that might load images that don’t exist, the warning message will become annoying.

Is there any way to remove this warning? We have particle images in our game and only use 1x versions. The game is constantly warning that it cannot find the 2x version. I think this is a bug. The 1x versions of the images are loaded properly, it just keeps warning that it cant find the 2x. We don’t need 2x versions for these particles. It should only produce the warning if the 1x image is missing in my opinion. Any ideas?

Hi @nahmeenstudios,

In my opinion, you should just include the @2x version of the particle. If it’s a particle for a particle effect, I can’t imagine its overall size would be more than 20 KB… but if you really don’t want to include it, you’ll have to accept the warning. The particle engine automatically looks for the proper version of particles, and there’s no way to opt out of that.

Best regards,

Brent

The question is…  the reason CoronaSDK insists to print out the warning log for?

Presumably they insist on it because for most people it would be better to be notified that you’ve overlooked an image in your project.

If you were to be able to opt out entirely then sure you wouldn’t get the message about your particles, but you also wouldn’t get it for your background or main character. If you don’t have the device to test on it can be easy to overlook it altogether.

In my example the image is there, just the 2x image is missing. Display.newImageRect chooses 2x if it is there but works fine with a 1x image if there is no 2x. The message isnt helpful. I purposely only have 1x particle images.

In reference to Alan Quiztix example, if you forgot the 2x version of your main character image then it would look horrible and blurry. If you launch a game with blurry images than it is the devs fault.

I think a more pertinent question is: why is your app is trying to load so many images that don’t exist?

For example, a news app that will download images dynamically during run time.

The app tries to display a image directly from a temp folder in case it has been downloaded earlier. 

Therefore, if it has not been downloaded before, this warning message is shown.

Well, I can’t help you hide the message, but I can help you avoid it.

At a small cost, you can first check to see if the image exists before you try to use it.

  1. Add this to your main.lua or early in the init/load process.

    function io.exists( fileName, base ) local base = base or system.DocumentsDirectory local fileName = fileName if( base ) then fileName = system.pathForFile( fileName, base ) end if not fileName then return false end local f=io.open(fileName,“r”) if (f == nil) then return false end io.close(f) return true end

  2. use it like this:

    if( io.exists( <path to file here> , system.TemporaryDirectory ) ) then – load from ‘disk’ else – download the image first end

I’ve also run into this with an app that has some images bundled into the build but can also download updated images when the app is running.

On Android, some files get packaged in the build in a manner that prevents you from checking if they exist. See section 5 of this blog post: http://coronalabs.com/blog/2013/02/13/faq-wednesday-sub-folder-and-file-access/

I experimented with several different solutions, including the one suggested in blog of naming the file picture1.png.txt and then doing a copy and rename. In the end, the cleanest most reliable solution for me was to just do a call to display.newImage and then check if the result is null. This produces those annoying warnings but they’re not visible to the average app user.

thanks, roaminggamer

I thought about checking if the file exists first like you suggested. The problem is about the “small cost”. I don’t want to make the io check because it might affect the performance a bit just for turning off the warning log.

However, after a second thought, I should use this io check only for “Simulator” so I won’t see the annoying warning again for my own testing and that’s good enough.