Skip to content

Commit b28711a

Browse files
committed
core: make findFilePath more robust
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]>
1 parent f10a5a8 commit b28711a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

rwcore/platform/FileIndex.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,22 @@ void FileIndex::indexTree(const std::filesystem::path &path) {
3939
}
4040

4141
const FileIndex::IndexedData *FileIndex::getIndexedDataAt(const std::string &filePath) const {
42-
auto normPath = normalizeFilePath(filePath);
43-
return &indexedData_.at(normPath);
42+
std::string normPath = normalizeFilePath(filePath);
43+
try {
44+
return &indexedData_.at(normPath);
45+
}
46+
catch (...) {
47+
RW_ERROR("Missing file: " << normPath);
48+
return nullptr;
49+
}
4450
}
4551

4652
std::filesystem::path FileIndex::findFilePath(const std::string &filePath) const {
47-
return getIndexedDataAt(filePath)->path;
53+
auto idxData = getIndexedDataAt(filePath);
54+
if (!idxData)
55+
return filePath;
56+
57+
return idxData->path;
4858
}
4959

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

0 commit comments

Comments
 (0)