How to use ofxThreadedImageLoader

I have an interesting situation. I’m trying to asynchronously load a ton of images from the web, like, not one image many times but lots of different images (100+).
I would ideally like to have a wrapper class that holds the image and it’s ofVBOMesh maybe the url for the image and other interesting things. So let’s say that I have a class ‘Tile’ and I have a ‘TileGroup’ class with a std::vector of Tiles I might need to add or remove some, after all. Now I want to load images into all of my tiles in the background so the framerate stays nice and smooth in the meantime, how would I accomplish this? I tried several methods and so far haven’t found a great answer.

  1. Give the ‘TileGroup’ class a ofxThreadedImageLoader object. Result: Loads everything successfully but it hangs while the ofxThreadedImageLoader object adds everything to the queue and then each image loads sequentially from first to last. It would be nice if there was no startup hang and if each image loaded at the same time. Also, if I use ofxThreadedImageLoader load new images over the old ones the size doesn’t get set back to 0x0 so I can’t tell if the anything new has come down the pipe yet.

  2. Give each ‘Tile’ an actual ofxThreadedImageLoader object. Result: Won’t compile because a std::vector copies everything you try to put into it and the ofxThreadedImageLoader has no sensible way to copy itself (manifested in the Poco::Mutex private copy constructor) . This makes sense, I mean, what if you copy it while it’s busy downloading an image, which images need to get updated and how do find the new one?

  3. Give each ‘Tile’ an ofxThreadedImageLoader* to a ofxThreadedImageLoader on the heap/in the ‘TileGroup’/somewhere that won’t be copied. Result: Fails to load all of the images. I don’t understand what’s going on with this one, but every ‘Tile’ gets the image from the first url to get passed to any of the ofxThreadedImageLoader objects as soon as it loads.

  4. Create an ofxThreadedImageLoader object only in the ‘asynch load my image and set other properties’ method of my ‘Tile’ class. Result: Crashes, I think, because the ofxThreadedImageLoader gets deallocated off the stack before it gets anything back.

What I want to know is how I can achieve true async loading that doesn’t block the main thread ever and actually loads all of the images I pass to it. Ideally, I would also like to know when the image is done loading too.

By the way, this is my first ‘real’ OpenFrameworks project and I’m building it on a mac with Xcode 5.0.

Is this useful?

https://github.com/RandomEtc/modestmaps-of

That looks cool. My app is creating more of a random collage than something specifically from a map, but it looks like the loading technique used in the example might work well for me. Thanks!

Never-the-less, is the jury still out on how to get true concurrency on from ofxThreadedImageLoader?

I came up with another method of using the ofxThreadedImageLoader that I hadn’t tried before: use a static class member ofxThreadedImageLoader in my image-container class to load all of the images… this method doesn’t work either. I get an exception in Mutex_POSIX.h - throw SystemException(“cannot lock mutex”);

Anyone have any idea what’s going here?

I’ve done a few things in the past to get around this:

  1. Download all the images temporarily then load them
  2. Load all the images into a temporary place holder and when they have loaded, notify the tilegroup and save a copy of the new image into one of your tiles.

Hope this helps. And if you find a way to do it directly, I’d love to hear about your solution.

@BenVanCitters Having the same exact issue trying to use ofxThreadedImageLoader in a class. Any luck?
Thanks!