From e04f7eb1f83c8e0f82492a45bf131080e9bc4968 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 29 May 2006 02:53:50 +0000 Subject: [PATCH] Unbind buffer from source before we attempt to delete it, allow re-resolving clips waiting to be unloaded. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4155 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/java/com/threerings/openal/ClipBuffer.java | 13 ++++++------- src/java/com/threerings/openal/Sound.java | 3 ++- src/java/com/threerings/openal/SoundManager.java | 9 +++++++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/java/com/threerings/openal/ClipBuffer.java b/src/java/com/threerings/openal/ClipBuffer.java index 9e800748f..f78cebe70 100644 --- a/src/java/com/threerings/openal/ClipBuffer.java +++ b/src/java/com/threerings/openal/ClipBuffer.java @@ -124,6 +124,12 @@ public class ClipBuffer */ public void resolve (Observer observer) { + // if we were waiting to unload, cancel that + if (_state == UNLOADING) { + _state = LOADED; + _manager.restoreClip(this); + } + // if we're already loaded, this is easy if (_state == LOADED) { if (observer != null) { @@ -132,13 +138,6 @@ public class ClipBuffer return; } - // this shouldn't happen - if (_state == UNLOADING) { - Log.warning("Tried to resolve buffer in the process of " + - "unloading [key=" + getKey() + "]."); - return; - } - // queue up the observer if (observer != null) { _observers.add(observer); diff --git a/src/java/com/threerings/openal/Sound.java b/src/java/com/threerings/openal/Sound.java index 05458240f..ae892c8d0 100644 --- a/src/java/com/threerings/openal/Sound.java +++ b/src/java/com/threerings/openal/Sound.java @@ -258,8 +258,9 @@ public class Sound if (_sourceId != -1 && AL10.alGetSourcei(_sourceId, AL10.AL_SOURCE_STATE) == AL10.AL_STOPPED) { - _sourceId = -1; + AL10.alSourcei(_sourceId, AL10.AL_BUFFER, 0); _buffer.sourceUnbound(); + _sourceId = -1; return true; } return false; diff --git a/src/java/com/threerings/openal/SoundManager.java b/src/java/com/threerings/openal/SoundManager.java index ff438361d..3f2a8cc25 100644 --- a/src/java/com/threerings/openal/SoundManager.java +++ b/src/java/com/threerings/openal/SoundManager.java @@ -247,6 +247,15 @@ public class SoundManager }); } + /** + * Adds the supplied clip buffer back to the cache after it has been marked + * for disposal and subsequently re-requested. + */ + protected void restoreClip (ClipBuffer buffer) + { + _clips.put(buffer.getKey(), buffer); + } + /** * Adds a stream to the list maintained by the manager. Called by streams * when they are created.