From 0878d87ac7d1a5fe8b1e529796eeaeba6855dc6a Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 12 May 2016 11:09:52 -0700 Subject: [PATCH 1/2] remove some unnecessary dependencies --- libraries/animation/CMakeLists.txt | 2 +- libraries/entities-renderer/CMakeLists.txt | 2 +- libraries/entities/CMakeLists.txt | 2 +- libraries/fbx/CMakeLists.txt | 2 +- libraries/model-networking/CMakeLists.txt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/animation/CMakeLists.txt b/libraries/animation/CMakeLists.txt index 3cf7bfa295..dd2fdaaabc 100644 --- a/libraries/animation/CMakeLists.txt +++ b/libraries/animation/CMakeLists.txt @@ -1,3 +1,3 @@ set(TARGET_NAME animation) setup_hifi_library(Network Script) -link_hifi_libraries(shared gpu model fbx) +link_hifi_libraries(shared model fbx) diff --git a/libraries/entities-renderer/CMakeLists.txt b/libraries/entities-renderer/CMakeLists.txt index 7023d285ff..bb90c04c95 100644 --- a/libraries/entities-renderer/CMakeLists.txt +++ b/libraries/entities-renderer/CMakeLists.txt @@ -1,7 +1,7 @@ set(TARGET_NAME entities-renderer) AUTOSCRIBE_SHADER_LIB(gpu model render render-utils) setup_hifi_library(Widgets Network Script) -link_hifi_libraries(shared gpu procedural model model-networking script-engine render render-utils gl) +link_hifi_libraries(shared gpu procedural model model-networking script-engine render render-utils) target_bullet() diff --git a/libraries/entities/CMakeLists.txt b/libraries/entities/CMakeLists.txt index 7bea5c6088..1230fe8146 100644 --- a/libraries/entities/CMakeLists.txt +++ b/libraries/entities/CMakeLists.txt @@ -1,6 +1,6 @@ set(TARGET_NAME entities) setup_hifi_library(Network Script) -link_hifi_libraries(avatars shared audio octree gpu model fbx networking animation) +link_hifi_libraries(avatars shared audio octree model fbx networking animation) target_bullet() diff --git a/libraries/fbx/CMakeLists.txt b/libraries/fbx/CMakeLists.txt index e10b6bcfd5..d9f4aaf03e 100644 --- a/libraries/fbx/CMakeLists.txt +++ b/libraries/fbx/CMakeLists.txt @@ -1,3 +1,3 @@ set(TARGET_NAME fbx) setup_hifi_library() -link_hifi_libraries(shared gpu model networking octree) +link_hifi_libraries(shared model networking) diff --git a/libraries/model-networking/CMakeLists.txt b/libraries/model-networking/CMakeLists.txt index 29ab17f2ec..ed8cd7b5f9 100644 --- a/libraries/model-networking/CMakeLists.txt +++ b/libraries/model-networking/CMakeLists.txt @@ -1,4 +1,4 @@ set(TARGET_NAME model-networking) setup_hifi_library() -link_hifi_libraries(shared networking gpu model fbx) +link_hifi_libraries(shared networking model fbx) From 419ff3bbeaf7dbf2d11408c1a442c6f976166702 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 12 May 2016 13:49:43 -0700 Subject: [PATCH 2/2] Track request lifetime in lambda callbacks --- libraries/networking/src/AssetClient.cpp | 4 +--- libraries/networking/src/AssetRequest.cpp | 14 +++++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/libraries/networking/src/AssetClient.cpp b/libraries/networking/src/AssetClient.cpp index 080b0c9b90..c4ec0ad61e 100644 --- a/libraries/networking/src/AssetClient.cpp +++ b/libraries/networking/src/AssetClient.cpp @@ -202,7 +202,7 @@ AssetUpload* AssetClient::createUpload(const QByteArray& data) { } MessageID AssetClient::getAsset(const QString& hash, DataOffset start, DataOffset end, - ReceivedAssetCallback callback, ProgressCallback progressCallback) { + ReceivedAssetCallback callback, ProgressCallback progressCallback) { Q_ASSERT(QThread::currentThread() == thread()); if (hash.length() != SHA256_HASH_HEX_LENGTH) { @@ -238,8 +238,6 @@ MessageID AssetClient::getAsset(const QString& hash, DataOffset start, DataOffse callback(false, AssetServerError::NoError, QByteArray()); return INVALID_MESSAGE_ID; } - - } MessageID AssetClient::getAssetInfo(const QString& hash, GetInfoCallback callback) { diff --git a/libraries/networking/src/AssetRequest.cpp b/libraries/networking/src/AssetRequest.cpp index 594c471196..4f0e812031 100644 --- a/libraries/networking/src/AssetRequest.cpp +++ b/libraries/networking/src/AssetRequest.cpp @@ -106,9 +106,13 @@ void AssetRequest::start() { int start = 0, end = _info.size; auto assetClient = DependencyManager::get(); + auto that = QPointer(this); // Used to track the request's lifetime _assetRequestID = assetClient->getAsset(_hash, start, end, - [this, start, end](bool responseReceived, AssetServerError serverError, const QByteArray& data) { - + [this, that, start, end](bool responseReceived, AssetServerError serverError, const QByteArray& data) { + if (!that) { + // If the request is dead, return + return; + } _assetRequestID = AssetClient::INVALID_MESSAGE_ID; if (!responseReceived) { @@ -148,7 +152,11 @@ void AssetRequest::start() { _state = Finished; emit finished(this); - }, [this](qint64 totalReceived, qint64 total) { + }, [this, that](qint64 totalReceived, qint64 total) { + if (!that) { + // If the request is dead, return + return; + } emit progress(totalReceived, total); }); });