Skip to content

Commit 28d71ff

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 28d71ff

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

rwcore/platform/FileIndex.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,20 @@ 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+
} catch (...) {
46+
RW_ERROR("Missing file: " << normPath);
47+
return nullptr;
48+
}
4449
}
4550

4651
std::filesystem::path FileIndex::findFilePath(const std::string &filePath) const {
47-
return getIndexedDataAt(filePath)->path;
52+
auto idxData = getIndexedDataAt(filePath);
53+
if (!idxData) return filePath;
54+
55+
return idxData->path;
4856
}
4957

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

0 commit comments

Comments
 (0)