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.
-
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.
-
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?
-
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.
-
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.