On x86, it may fail to initialize QImage on worker thread. (Rare in x64)
The probability increases when parallel processing is performed over the number of cores of the CPU.
This occurs not only by reading from an image file, but also by initializing a plain QImage by specifying its size, or simply by calling QImage::copy().
This is a code to avoid it. Of course it is not perfect. Please tell me a better way.
QImage createImageAsync(QString path)
{
QImageReader reader(path);
if(!reader.canRead())
return QImage();
// QImage processing sometimes fails
QImage src;
int count = 0;
do {
src = reader.read();
if(!src.isNull())
break;
if(src.isNull() && count++ < 1000) {
QThread::currentThread()->usleep(1000);
continue;
}
return QImage();
} while(1);
return src;
}