From f3efd3726470ca3e46209a58e8443f80cc891f3c Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Wed, 20 Feb 2019 19:45:11 -0800 Subject: [PATCH] Python: Fix crash when deleting files owned by library --- CHANGES | 1 + src/platform/python/mgba/core.py | 10 ++++++++-- src/platform/python/mgba/vfs.py | 7 ++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index db6a4acff..e8cdfd2ca 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,7 @@ Bugfixes: - GBA SIO: Prevent writing read-only multiplayer bits - Qt: Fix color picking in sprite view (fixes mgba.io/i/1307) - GB: Fix crash when accessing SRAM if no save loaded and cartridge has no SRAM + - Python: Fix crash when deleting files owned by library Misc: - GBA Savedata: EEPROM performance fixes - GBA Savedata: Automatically map 1Mbit Flash files as 1Mbit Flash diff --git a/src/platform/python/mgba/core.py b/src/platform/python/mgba/core.py index 7a0672322..589ef0cb3 100644 --- a/src/platform/python/mgba/core.py +++ b/src/platform/python/mgba/core.py @@ -180,11 +180,17 @@ class Core(object): @protected def load_bios(self, vfile, id=0): - return bool(self._core.loadBIOS(self._core, vfile.handle, id)) + res = bool(self._core.loadBIOS(self._core, vfile.handle, id)) + if res: + vfile._claimed = True + return res @protected def load_save(self, vfile): - return bool(self._core.loadSave(self._core, vfile.handle)) + res = bool(self._core.loadSave(self._core, vfile.handle)) + if res: + vfile._claimed = True + return res @protected def load_temporary_save(self, vfile): diff --git a/src/platform/python/mgba/vfs.py b/src/platform/python/mgba/vfs.py index 2381a0aee..bab78c799 100644 --- a/src/platform/python/mgba/vfs.py +++ b/src/platform/python/mgba/vfs.py @@ -112,11 +112,16 @@ class VFile: def __init__(self, vf, _no_gc=None): self.handle = vf self._no_gc = _no_gc + self._claimed = False def __del__(self): - self.close() + if not self._claimed: + self.close() def close(self): + if self._claimed: + return False + self._claimed = True return bool(self.handle.close(self.handle)) def seek(self, offset, whence):