fix: bad cacheing behaviour

This commit is contained in:
minjaesong
2024-04-02 23:23:16 +09:00
parent 94152afcac
commit 9a8c91562e
6 changed files with 21 additions and 10 deletions

View File

@@ -210,7 +210,9 @@ class MixerTrackProcessor(bufferSize: Int, val rate: Int, val track: TerrarumAud
allocateStreamBuf(track)
}
streamBuf!!.fetchBytes()
if (track.currentTrack == null) throw IllegalStateException("Track ${track.name} is playing but also has null music track")
streamBuf?.fetchBytes() ?: throw NullPointerException("Null StreamBuf for ${track.name}")
}
var samplesL1: FloatArray

View File

@@ -8,11 +8,11 @@ class MusicCache(val trackName: String) : Disposable {
private val cache = HashMap<String, MusicContainer>()
fun getOrPut(music: MusicContainer?): MusicContainer? {
if (music != null && music.toRAM) { // for now only the on-the-RAM tracks are getting cached
println("Cacheing music ${music.name} for track $trackName")
if (music != null && !music.toRAM)
return music
if (music != null && music.toRAM) // for now only the on-the-RAM tracks are getting cached
return cache.getOrPut(music.name) { music.makeCopy() }
}
else return null
return null
}
override fun dispose() {

View File

@@ -44,12 +44,18 @@ class TerrarumAudioMixerTrack(
var currentTrack: MusicContainer? = null
set(value) {
field = musicCache.getOrPut(value)
field = if (value == null)
null
else
musicCache.getOrPut(value)
}
var nextTrack: MusicContainer? = null
set(value) {
field = musicCache.getOrPut(value)
field = if (value == null)
null
else
musicCache.getOrPut(value)
}
var volume: TrackVolume = 1.0