From c9a556935111c36d5cd31b6b70d31aa65c75207c Mon Sep 17 00:00:00 2001 From: Jamie Bliss Date: Tue, 18 May 2021 12:11:26 -0400 Subject: [PATCH 1/2] Fix asset caching Closes #623 --- ppb/assetlib.py | 12 +++++------- ppb/systems/sound.py | 2 ++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ppb/assetlib.py b/ppb/assetlib.py index 864070ab..f14a655f 100644 --- a/ppb/assetlib.py +++ b/ppb/assetlib.py @@ -277,13 +277,11 @@ def __new__(cls, name): try: return _asset_cache[(clsname, name)] except KeyError: - inst = super().__new__(cls) - _asset_cache[(clsname, name)] = inst - return inst - - def __init__(self, name): - self.name = str(name) - self._start() + self = super().__new__(cls) + self.name = str(name) + _asset_cache[(clsname, name)] = self + self._start() + return self def __repr__(self): return f"<{type(self).__name__} name={self.name!r}{' loaded' if self.is_loaded() else ''} at 0x{id(self):x}>" diff --git a/ppb/systems/sound.py b/ppb/systems/sound.py index 7c541cba..df3ea56d 100644 --- a/ppb/systems/sound.py +++ b/ppb/systems/sound.py @@ -28,6 +28,7 @@ class Sound(assetlib.Asset): # This is wrapping a ctypes.POINTER(Mix_Chunk) def background_parse(self, data): + print("Sound.background_parse", repr(self), flush=True) file = rw_from_object(io.BytesIO(data)) # ^^^^ is a pure-python emulation, does not need cleanup. return mix_call( @@ -84,6 +85,7 @@ def allocated_channels(self, value): mix_call(Mix_AllocateChannels, value) def __enter__(self): + print("SoundController.__enter__", repr(self), flush=True) super().__enter__() mix_call( Mix_OpenAudio, From e316a73760f508dd711a83d2bc70266e62ae6c17 Mon Sep 17 00:00:00 2001 From: Jamie Bliss Date: Tue, 18 May 2021 22:07:57 -0400 Subject: [PATCH 2/2] Remove some debugging --- ppb/systems/sound.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/ppb/systems/sound.py b/ppb/systems/sound.py index df3ea56d..7c541cba 100644 --- a/ppb/systems/sound.py +++ b/ppb/systems/sound.py @@ -28,7 +28,6 @@ class Sound(assetlib.Asset): # This is wrapping a ctypes.POINTER(Mix_Chunk) def background_parse(self, data): - print("Sound.background_parse", repr(self), flush=True) file = rw_from_object(io.BytesIO(data)) # ^^^^ is a pure-python emulation, does not need cleanup. return mix_call( @@ -85,7 +84,6 @@ def allocated_channels(self, value): mix_call(Mix_AllocateChannels, value) def __enter__(self): - print("SoundController.__enter__", repr(self), flush=True) super().__enter__() mix_call( Mix_OpenAudio,