Fixed crash when loading invalid image. (#160)

* Fixed crash when loading invalid image.

* Fixed crash when loading invalid image (part2).
This commit is contained in:
antonio-111 2020-03-11 10:59:42 +03:00 committed by GitHub
parent 29597353ec
commit dac9480a65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,22 +36,24 @@ QImage ImageHandler::extractQImage(QObject *imageObj, int offsetX, int offsetY,
QTime timer;
timer.start();
QSharedPointer<QQuickItemGrabResult> result = item->grabToImage();
pendingGrabbersLocker.lockForWrite();
pendingGrabbers << result.data();
pendingGrabbersLocker.unlock();
connect(result.data(), &QQuickItemGrabResult::ready, this, &ImageHandler::imageGrabberReady);
while (timer.elapsed() < 1000) {
pendingGrabbersLocker.lockForRead();
if (!pendingGrabbers.contains(result.data())) {
pendingGrabbersLocker.unlock();
break;
}
if (result) {
pendingGrabbersLocker.lockForWrite();
pendingGrabbers << result.data();
pendingGrabbersLocker.unlock();
qApp->processEvents();
QThread::yieldCurrentThread();
connect(result.data(), &QQuickItemGrabResult::ready, this, &ImageHandler::imageGrabberReady);
while (timer.elapsed() < 1000) {
pendingGrabbersLocker.lockForRead();
if (!pendingGrabbers.contains(result.data())) {
pendingGrabbersLocker.unlock();
break;
}
pendingGrabbersLocker.unlock();
qApp->processEvents();
QThread::yieldCurrentThread();
}
img = result->image();
}
img = result->image();
#else // QT_VERSION >= 0x050000
QGraphicsObject *item = qobject_cast<QGraphicsObject*>(imageObj);