Skip to content

Commit

Permalink
fix: set parent pointer on file to be the same shared pointer from `m…
Browse files Browse the repository at this point in the history
…FileToArchive` (#452)

* fix: set parent pointer on file to be the same shared pointer from `mFileToArchive`

* make sure to set it in non-raw loadfile too
  • Loading branch information
briaguya-ai authored Feb 21, 2024
1 parent be3a87e commit 972b535
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
22 changes: 8 additions & 14 deletions src/resource/archive/ArchiveManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ std::shared_ptr<File> ArchiveManager::LoadFile(const std::string& filePath) {
return nullptr;
}

const auto archive = mFileToArchive[CRC64(filePath.c_str())];
if (archive == nullptr) {
return nullptr;
}

return archive->LoadFile(filePath);
return LoadFile(CRC64(filePath.c_str()));
}

std::shared_ptr<File> ArchiveManager::LoadFile(uint64_t hash) {
Expand All @@ -59,20 +54,17 @@ std::shared_ptr<File> ArchiveManager::LoadFile(uint64_t hash) {
return nullptr;
}

return archive->LoadFile(hash);
auto file = archive->LoadFile(hash);
file->Parent = archive;
return file;
}

std::shared_ptr<File> ArchiveManager::LoadFileRaw(const std::string& filePath) {
if (filePath == "") {
return nullptr;
}

const auto archive = mFileToArchive[CRC64(filePath.c_str())];
if (archive == nullptr) {
return nullptr;
}

return archive->LoadFileRaw(filePath);
return LoadFileRaw(CRC64(filePath.c_str()));
}

std::shared_ptr<File> ArchiveManager::LoadFileRaw(uint64_t hash) {
Expand All @@ -81,7 +73,9 @@ std::shared_ptr<File> ArchiveManager::LoadFileRaw(uint64_t hash) {
return nullptr;
}

return archive->LoadFileRaw(hash);
auto file = archive->LoadFileRaw(hash);
file->Parent = archive;
return file;
}

bool ArchiveManager::HasFile(const std::string& filePath) {
Expand Down
1 change: 0 additions & 1 deletion src/resource/archive/O2rArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ std::shared_ptr<File> O2rArchive::LoadFileRaw(const std::string& filePath) {
SPDLOG_TRACE("Error closing file {} in zip archive {}.", filePath, GetPath());
}

fileToLoad->Parent = dynamic_pointer_cast<Archive>(std::make_shared<O2rArchive>(std::move(*this)));
fileToLoad->IsLoaded = true;

return fileToLoad;
Expand Down
1 change: 0 additions & 1 deletion src/resource/archive/OtrArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ std::shared_ptr<File> OtrArchive::LoadFileRaw(const std::string& filePath) {
SPDLOG_ERROR("({}) Failed to close file {} from mpq archive {}", GetLastError(), filePath, GetPath());
}

fileToLoad->Parent = dynamic_pointer_cast<Archive>(std::make_shared<OtrArchive>(std::move(*this)));
fileToLoad->IsLoaded = true;

return fileToLoad;
Expand Down

0 comments on commit 972b535

Please sign in to comment.