mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-19 09:19:05 +02:00
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) <noreply@anthropic.com>
This commit is contained in:
1 parent
db071361b0
commit
84f64a9fdf
3 files changed
+34
No files matched your search
@@ -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);
|
||||
|
||||
@@ -1451,6 +1451,12 @@ void PPGeImage::Free() {
|
||||
}
|
||||
}
|
||||
|
||||
void PPGeImage::Forget() {
|
||||
texture_ = 0;
|
||||
loadFailed_ = false;
|
||||
loadedTextures_.erase(std::remove(loadedTextures_.begin(), loadedTextures_.end(), this), loadedTextures_.end());
|
||||
}
|
||||
|
||||
void PPGeImage::DoState(PointerWrap &p) {
|
||||
auto s = p.Section("PPGeImage", 1, 2);
|
||||
if (!s)
|
||||
|
||||
@@ -122,6 +122,8 @@ public:
|
||||
// Does not normally need to be called (except to force preloading.)
|
||||
bool Load();
|
||||
void Free();
|
||||
// Drops the texture without freeing its memory, which a savestate load has already replaced.
|
||||
void Forget();
|
||||
bool IsValid();
|
||||
|
||||
void DoState(PointerWrap &p);
|
||||
|
||||
Reference in new issue
Block a user