Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

AssetAPI: Fix bug where failed asset loads left their asset transfers…

… into the transfer map incorrectly indefinately.
  • Loading branch information...
commit 444aed7e74e02ecd3818cfd09fef96d29b92a7d8 1 parent 1bfd6fc
@jonnenauha jonnenauha authored
Showing with 21 additions and 31 deletions.
  1. +13 −25 src/Core/Asset/AssetAPI.cpp
  2. +8 −6 src/Core/Asset/IAsset.cpp
View
38 src/Core/Asset/AssetAPI.cpp
@@ -1205,29 +1205,19 @@ void AssetAPI::AssetTransferCompleted(IAssetTransfer *transfer_)
// Tell everyone this transfer has now been downloaded. Note that when this signal is fired, the asset dependencies may not yet be loaded.
transfer->EmitAssetDownloaded();
+ bool success = false;
const u8 *data = (transfer->rawAssetData.size() > 0 ? &transfer->rawAssetData[0] : 0);
if (data)
- transfer->asset->LoadFromFileInMemory(data, transfer->rawAssetData.size());
+ success = transfer->asset->LoadFromFileInMemory(data, transfer->rawAssetData.size());
else
- transfer->asset->LoadFromFile(transfer->asset->DiskSource());
+ success = transfer->asset->LoadFromFile(transfer->asset->DiskSource());
- //bool success = transfer->asset->LoadFromFileInMemory(data, transfer->rawAssetData.size());
- //if (!success)
- //{
- // QString error("AssetAPI: Failed to load " + transfer->assetType + " '" + transfer->source.ref + "' from asset data.");
- // transfer->EmitAssetFailed(error);
- // return;
- //}
-
- //if (diskSourceChangeWatcher && !transfer->asset->DiskSource().isEmpty())
- // diskSourceChangeWatcher->addPath(transfer->asset->DiskSource());
-
- //// If this asset depends on any other assets, we have to make asset requests for those assets as well (and all assets that they refer to, and so on).
- //RequestAssetDependencies(transfer->asset);
-
- //// If we don't have any outstanding dependencies, succeed and remove the transfer
- //if (NumPendingDependencies(transfer->asset) == 0)
- // AssetDependenciesCompleted(transfer);
+ // If the load from either of in memory data or file data failed, update the internal state.
+ // Otherwise the transfer will be left dangling in currentTransfers. For successful loads
+ // we do no need to call AssetLoadCompleted because success can mean asynchronous loading,
+ // in which case the call will arrive once the asynchronous loading is completed.
+ if (!success)
+ AssetLoadFailed(transfer->asset->Name());
}
void AssetAPI::AssetTransferFailed(IAssetTransfer *transfer, QString reason)
@@ -1322,9 +1312,8 @@ void AssetAPI::AssetLoadCompleted(const QString assetRef)
// If we don't have any outstanding dependencies
// for the transfer, succeed and remove the transfer
- if (iter != currentTransfers.end())
- if (!HasPendingDependencies(asset))
- AssetDependenciesCompleted(iter->second);
+ if (iter != currentTransfers.end() && !HasPendingDependencies(asset))
+ AssetDependenciesCompleted(iter->second);
}
else
LogError("AssetAPI: Asset \"" + assetRef + "\" load completed, but no corresponding transfer or existing asset is being tracked!");
@@ -1338,9 +1327,8 @@ void AssetAPI::AssetLoadFailed(const QString assetRef)
if (iter != currentTransfers.end())
{
AssetTransferPtr transfer = iter->second;
-
- QString error("AssetAPI: Failed to load " + transfer->assetType + " '" + transfer->source.ref + "' from asset data.");
- transfer->EmitAssetFailed(error);
+ transfer->EmitAssetFailed("Failed to load " + transfer->assetType + " '" + transfer->source.ref + "' from asset data.");
+ currentTransfers.erase(iter);
}
else if (iter2 != assets.end())
LogError("AssetAPI: Failed to reload asset '" + iter2->second->Name());
View
14 src/Core/Asset/IAsset.cpp
@@ -139,6 +139,12 @@ bool IAsset::LoadFromFile(QString filename)
{
PROFILE(IAsset_LoadFromFile);
filename = filename.trimmed(); ///\todo Sanitate.
+ if (filename.isEmpty())
+ {
+ LogDebug("LoadFromFile failed for asset \"" + Name() + "\", given file path is empty!");
+ return false;
+ }
+
std::vector<u8> fileData;
bool success = LoadFileToVector(filename, fileData);
if (!success)
@@ -167,12 +173,8 @@ bool IAsset::LoadFromFileInMemory(const u8 *data, size_t numBytes, bool allowAsy
LogDebug("LoadFromFileInMemory failed for asset \"" + ToString() + "\"! No data present!");
return false;
}
-
- bool success = DeserializeFromData(data, numBytes, allowAsynchronous);
- /// Automatically call AssetAPI::AssetLoadFailed if load failed.
- if (!success)
- assetAPI->AssetLoadFailed(Name());
- return success;
+
+ return DeserializeFromData(data, numBytes, allowAsynchronous);
}
void IAsset::DependencyLoaded(AssetPtr dependee)
Please sign in to comment.
Something went wrong with that request. Please try again.