Savedata: Don't free stale icon textures after a state load

The old icons stayed in PPGe's decimation list with kernel addresses from
before the load, and got freed out of whatever the loaded state had there.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Henrik RydgårdandClaude Opus 5.5 committed 2026-09-28 09:34:05 -06:00
1 parent db071361b0
commit 84f64a9fdf
3 files changed
+34

No files matched your search

+26
View File
@@ -1958,6 +1958,32 @@ void SavedataParam::DoState(PointerWrap &p) {
if (!s)
return;
if (p.mode == p.MODE_READ) {
// The load replaces kernel memory, so the icons' texture addresses now belong to whatever
// the loaded state allocated there. Drop them without freeing those.
std::vector<PPGeImage *> oldTextures;
for (int i = 0; saveDataList && i < saveDataListCount; i++) {
if (saveDataList[i].texture) {
oldTextures.push_back(saveDataList[i].texture);
saveDataList[i].texture = nullptr;
}
}
if (noSaveIcon) {
oldTextures.push_back(noSaveIcon->texture);
delete noSaveIcon;
noSaveIcon = nullptr;
}
// Entries may share noSaveIcon's image.
std::sort(oldTextures.begin(), oldTextures.end());
oldTextures.erase(std::unique(oldTextures.begin(), oldTextures.end()), oldTextures.end());
for (PPGeImage *texture : oldTextures) {
if (texture) {
texture->Forget();
delete texture;
}
}
}
// pspParam is handled in PSPSaveDialog.
Do(p, selectedSave);
Do(p, saveDataListCount);