Skip to content

Commit 972b535

Browse files
authored
fix: set parent pointer on file to be the same shared pointer from mFileToArchive (Kenix3#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
1 parent be3a87e commit 972b535

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

src/resource/archive/ArchiveManager.cpp

+8-14
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@ std::shared_ptr<File> ArchiveManager::LoadFile(const std::string& filePath) {
4545
return nullptr;
4646
}
4747

48-
const auto archive = mFileToArchive[CRC64(filePath.c_str())];
49-
if (archive == nullptr) {
50-
return nullptr;
51-
}
52-
53-
return archive->LoadFile(filePath);
48+
return LoadFile(CRC64(filePath.c_str()));
5449
}
5550

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

62-
return archive->LoadFile(hash);
57+
auto file = archive->LoadFile(hash);
58+
file->Parent = archive;
59+
return file;
6360
}
6461

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

70-
const auto archive = mFileToArchive[CRC64(filePath.c_str())];
71-
if (archive == nullptr) {
72-
return nullptr;
73-
}
74-
75-
return archive->LoadFileRaw(filePath);
67+
return LoadFileRaw(CRC64(filePath.c_str()));
7668
}
7769

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

84-
return archive->LoadFileRaw(hash);
76+
auto file = archive->LoadFileRaw(hash);
77+
file->Parent = archive;
78+
return file;
8579
}
8680

8781
bool ArchiveManager::HasFile(const std::string& filePath) {

src/resource/archive/O2rArchive.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ std::shared_ptr<File> O2rArchive::LoadFileRaw(const std::string& filePath) {
5353
SPDLOG_TRACE("Error closing file {} in zip archive {}.", filePath, GetPath());
5454
}
5555

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

5958
return fileToLoad;

src/resource/archive/OtrArchive.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ std::shared_ptr<File> OtrArchive::LoadFileRaw(const std::string& filePath) {
5050
SPDLOG_ERROR("({}) Failed to close file {} from mpq archive {}", GetLastError(), filePath, GetPath());
5151
}
5252

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

5655
return fileToLoad;

0 commit comments

Comments
 (0)