Skip to content

Commit 6f5302f

Browse files
nyalldawsonrldhont
authored andcommittedMay 21, 2020
Workaround double slot calling causing empty replies to overwrite
valid reply content
1 parent d353850 commit 6f5302f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed
 

‎src/core/qgsabstractcontentcache.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,12 @@ class CORE_EXPORT QgsAbstractContentCache : public QgsAbstractContentCacheBase
402402
if ( ok )
403403
{
404404
// read the content data
405-
mRemoteContentCache.insert( path, new QByteArray( reply->readAll() ) );
405+
const QByteArray ba = reply->readAll();
406+
407+
// because of the fragility listed below in waitForTaskFinished, this slot may get called twice. In that case
408+
// the second time will have an empty reply (we've already read it all...)
409+
if ( !ba.isEmpty() )
410+
mRemoteContentCache.insert( path, new QByteArray( ba ) );
406411
}
407412
QMetaObject::invokeMethod( const_cast< QgsAbstractContentCacheBase * >( qobject_cast< const QgsAbstractContentCacheBase * >( this ) ), "onRemoteContentFetched", Qt::QueuedConnection, Q_ARG( QString, path ), Q_ARG( bool, true ) );
408413
} );
@@ -466,6 +471,8 @@ class CORE_EXPORT QgsAbstractContentCache : public QgsAbstractContentCacheBase
466471
if ( task->status() == QgsTask::Complete )
467472
{
468473
// Fourth step, force the signal fetched to be sure reply has been checked
474+
475+
// ARGH this is BAD BAD BAD. The connection will get called twice as a result!!!
469476
task->fetched();
470477
return true;
471478
}

0 commit comments

Comments
 (0)
Please sign in to comment.