When I use the ofxThreadedImageLoader, the stopThread() function has no effect while there are more images to load. In my application it is possible that the app can be killed before all of the images have been loaded, if the imageLoader thread is not killed then a memory access violation occurs during app shutdown when pixels are being accessed from an object that has been deleted. Can’t the image loader’s threaded function be like so:
void ofxThreadedImageLoader::threadedFunction() {
setThreadName("ofxThreadedImageLoader " + ofToString(thread.get_id()));
ofImageLoaderEntry entry;
while( images_to_load_from_disk.receive(entry) && isThreadRunning() ) {
if(entry.image->load(entry.filename) ) {
images_to_update.send(entry);
}else{
ofLogError("ofxThreadedImageLoader") << "couldn't load file: \"" << entry.filename << "\"";
}
}
ofLogVerbose("ofxThreadedImageLoader") << "finishing thread on closed queue";
}
To check if a stopThread() has been called as well as new image entries?
The code that causes the access violation is when pixels are accessed and moved from the image defined in the imageLoader.loadFromDisk(image, filename) function and when the image object has been deleted.
I’ve made this change and my app shutdown fine now. I was wondering if this was a bug or am I using it incorrectly?