Skip to content

Commit

Permalink
core: make findFilePath more robust
Browse files Browse the repository at this point in the history
Do not crash, when asset is missing, just warn about it.
Game can work well without missing wav and mp3 files.

Also, the crash itself looks a bit mysterious, so now the game prints
name of the missing asset.

Signed-off-by: David Heidelberg <[email protected]>
  • Loading branch information
okias committed Nov 27, 2024
1 parent f10a5a8 commit 28d71ff
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions rwcore/platform/FileIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,20 @@ void FileIndex::indexTree(const std::filesystem::path &path) {
}

const FileIndex::IndexedData *FileIndex::getIndexedDataAt(const std::string &filePath) const {
auto normPath = normalizeFilePath(filePath);
return &indexedData_.at(normPath);
std::string normPath = normalizeFilePath(filePath);
try {
return &indexedData_.at(normPath);
} catch (...) {
RW_ERROR("Missing file: " << normPath);
return nullptr;
}
}

std::filesystem::path FileIndex::findFilePath(const std::string &filePath) const {
return getIndexedDataAt(filePath)->path;
auto idxData = getIndexedDataAt(filePath);
if (!idxData) return filePath;

return idxData->path;
}

FileContentsInfo FileIndex::openFileRaw(const std::string &filePath) const {
Expand Down

0 comments on commit 28d71ff

Please sign in to comment.