Fix crash if LoadFile fails
This commit is contained in:
parent
ceef4a9453
commit
85ea0c6706
|
@ -49,11 +49,16 @@ namespace Ship {
|
|||
std::shared_ptr<File> Archive::LoadFile(const std::string& filePath, bool includeParent, std::shared_ptr<File> FileToLoad) {
|
||||
HANDLE fileHandle = NULL;
|
||||
|
||||
if (FileToLoad == nullptr) {
|
||||
FileToLoad = std::make_shared<File>();
|
||||
FileToLoad->path = filePath;
|
||||
}
|
||||
|
||||
if (!SFileOpenFileEx(mainMPQ, filePath.c_str(), 0, &fileHandle)) {
|
||||
SPDLOG_ERROR("({}) Failed to open file {} from mpq archive {}", GetLastError(), filePath.c_str(), MainPath.c_str());
|
||||
std::unique_lock<std::mutex> Lock(FileToLoad->FileLoadMutex);
|
||||
FileToLoad->bHasLoadError = true;
|
||||
return nullptr;
|
||||
return FileToLoad;
|
||||
}
|
||||
|
||||
DWORD dwFileSize = SFileGetFileSize(fileHandle, 0);
|
||||
|
@ -67,18 +72,13 @@ namespace Ship {
|
|||
}
|
||||
std::unique_lock<std::mutex> Lock(FileToLoad->FileLoadMutex);
|
||||
FileToLoad->bHasLoadError = true;
|
||||
return nullptr;
|
||||
return FileToLoad;
|
||||
}
|
||||
|
||||
if (!SFileCloseFile(fileHandle)) {
|
||||
SPDLOG_ERROR("({}) Failed to close file {} from mpq archive {}", GetLastError(), filePath.c_str(), MainPath.c_str());
|
||||
}
|
||||
|
||||
if (FileToLoad == nullptr) {
|
||||
FileToLoad = std::make_shared<File>();
|
||||
FileToLoad->path = filePath;
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> Lock(FileToLoad->FileLoadMutex);
|
||||
FileToLoad->parent = includeParent ? shared_from_this() : nullptr;
|
||||
FileToLoad->buffer = fileData;
|
||||
|
@ -92,6 +92,11 @@ namespace Ship {
|
|||
HANDLE fileHandle = NULL;
|
||||
HANDLE mpqHandle = NULL;
|
||||
|
||||
if (FileToLoad == nullptr) {
|
||||
FileToLoad = std::make_shared<File>();
|
||||
FileToLoad->path = filePath;
|
||||
}
|
||||
|
||||
for(auto [path, handle] : mpqHandles) {
|
||||
if (SFileOpenFileEx(mpqHandle, filePath.c_str(), 0, &fileHandle)) {
|
||||
std::unique_lock Lock(FileToLoad->FileLoadMutex);
|
||||
|
@ -116,18 +121,13 @@ namespace Ship {
|
|||
}
|
||||
std::unique_lock<std::mutex> Lock(FileToLoad->FileLoadMutex);
|
||||
FileToLoad->bHasLoadError = true;
|
||||
return nullptr;
|
||||
return FileToLoad;
|
||||
}
|
||||
|
||||
if (!SFileCloseFile(fileHandle)) {
|
||||
SPDLOG_ERROR("({}) Failed to close file {} from mpq archive {}", GetLastError(), filePath.c_str(), MainPath.c_str());
|
||||
}
|
||||
|
||||
if (FileToLoad == nullptr) {
|
||||
FileToLoad = std::make_shared<File>();
|
||||
FileToLoad->path = filePath;
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> Lock(FileToLoad->FileLoadMutex);
|
||||
FileToLoad->parent = includeParent ? shared_from_this() : nullptr;
|
||||
FileToLoad->buffer = fileData;
|
||||
|
|
Loading…
Reference in New Issue