Code: Select all
void loadImage(const std::string& filename) {
std::ifstream file(filename,std::ifstream::binary);
std::ostringstream blob;
blob << file.rdbuf();
MagickWand* wand = NewMagickWand();
MagickReadImageBlob(wand,blob.str().data(),blob.str().size());
ExceptionType type;
const char* msg = MagickGetException(wand,&type);
if (type != UndefinedException) {
std::cout << "error: " << msg << std::endl;
} else {
std::cout << "successful" << std::endl;
}
DestroyMagickWand(wand);
}
void runner(boost::asio::io_service& service) {
service.run();
}
int main() {
boost::asio::io_service service;
boost::asio::io_service::work work(service);
service.post(boost::bind(&loadImage,std::string("test1.jpg")));
service.post(boost::bind(&loadImage,std::string("test2.jpg")));
boost::thread t1(boost::bind(&runner,boost::ref(service)));
boost::thread t2(boost::bind(&runner,boost::ref(service)));
std::cin.ignore();
return EXIT_SUCCESS;
}
no decode delegate for this image format `' @ error/blob.c/BlobToImage/358
Unfortunately, this error is hard to trigger. Often it occurs only on the first run of the application, but runs fine when executing it again. What I realized is, that this error only happens when the first images are loaded, so I could imagine that the error is due to some kind of global library initialization. Do I need to call a function for that? I tried to call MagickWandGenesis at the beginning of main, but that didn't fix it.
Thank you for any ideas about what I'm doing wrong. For now I'm using a workaround by avoiding to load images concurrently.