Skip to content

Commit 1881367

Browse files
committed
Fix missing asset data
Multiple assets can use the same asset file.
1 parent 67aff2d commit 1881367

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/project_p.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ bool ProjectPrivate::tryLoad(IProjectReader *reader)
7676

7777
// Get asset file names
7878
std::vector<std::string> assetNames;
79-
std::unordered_map<std::string, Asset *> assets;
79+
std::unordered_map<std::string, std::vector<Asset *>> assets; // multiple assets can use the same file
8080
const auto &targets = reader->targets();
8181

8282
for (auto target : targets) {
@@ -87,18 +87,18 @@ bool ProjectPrivate::tryLoad(IProjectReader *reader)
8787
auto it = std::find(assetNames.begin(), assetNames.end(), costume->fileName());
8888
if (it == assetNames.end()) {
8989
assetNames.push_back(costume->fileName());
90-
assets[assetNames.back()] = costume.get();
90+
assets[assetNames.back()] = { costume.get() };
9191
} else
92-
assets[*it] = costume.get();
92+
assets[*it].push_back(costume.get());
9393
}
9494

9595
for (auto sound : sounds) {
9696
auto it = std::find(assetNames.begin(), assetNames.end(), sound->fileName());
9797
if (it == assetNames.end()) {
9898
assetNames.push_back(sound->fileName());
99-
assets[assetNames.back()] = sound.get();
99+
assets[assetNames.back()] = { sound.get() };
100100
} else
101-
assets[*it] = sound.get();
101+
assets[*it].push_back(sound.get());
102102
}
103103
}
104104

@@ -120,10 +120,14 @@ bool ProjectPrivate::tryLoad(IProjectReader *reader)
120120

121121
// Load asset data
122122
for (size_t i = 0; i < assets.size(); i++) {
123-
const std::string &data = assetData[i];
124-
char *ptr = (char *)malloc(data.size() * sizeof(char));
125-
memcpy(ptr, data.data(), data.size() * sizeof(char));
126-
assets[assetNames[i]]->setData(data.size(), ptr);
123+
const std::vector<Asset *> &assetList = assets[assetNames[i]];
124+
125+
for (Asset *asset : assetList) {
126+
const std::string &data = assetData[i];
127+
char *ptr = (char *)malloc(data.size() * sizeof(char));
128+
memcpy(ptr, data.data(), data.size() * sizeof(char));
129+
asset->setData(data.size(), ptr);
130+
}
127131
}
128132

129133
} else {

0 commit comments

Comments
 (0)