Skip to content

Commit

Permalink
LoadFileToVector: Fix a bug that empty file size was an error case. I…
Browse files Browse the repository at this point in the history
…f the file is found but the contents is empty we return true but log a warning as this is a unusual situation. Add a single space to data/assets/dummy.txt so it wont spam these warnings on the local storage roaming step when tundra is ran.
  • Loading branch information
Jonne Nauha authored and Stinkfist0 committed Oct 4, 2013
1 parent 62d4f68 commit 94c8be7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions bin/data/assets/dummy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

8 changes: 5 additions & 3 deletions src/Core/TundraCore/Asset/AssetAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2304,16 +2304,18 @@ bool LoadFileToVector(const QString &filename, std::vector<u8> &dst)
qint64 fileSize = file.size();
if (fileSize <= 0)
{
LogError("AssetAPI::LoadFileToVector: Failed to read file '" + filename + "' of " + fileSize + " bytes in size.");
// If the file size is 0 this is still considered a success.
// Log out a warning for it either way as this is an unusual case.
LogWarning(QString("AssetAPI::LoadFileToVector: Source file '%1' exists but size is 0. Reading is reported to be successfull but read data is empty!").arg(filename));
file.close();
return false;
return true;
}
dst.resize(fileSize);
qint64 numRead = file.read((char*)&dst[0], fileSize);
file.close();
if (numRead < fileSize)
{
LogError("AssetAPI::LoadFileToVector: Failed to read " + QString::number(numRead) + " bytes from file '" + filename + "'.");
LogError(QString("AssetAPI::LoadFileToVector: Failed to read full %1 bytes from file '%2', instead read %3 bytes.").arg(fileSize).arg(filename).arg(numRead));
return false;
}
return true;
Expand Down

0 comments on commit 94c8be7

Please sign in to comment.