mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
fix sound loading crash, fixes #63
This commit is contained in:
parent
c955a15de6
commit
d29b6d043f
@ -225,8 +225,6 @@ class RenderWindow(
|
||||
connection.fireEvent(ResizeWindowEvent(previousSize = Vec2i(0, 0), size = window.size))
|
||||
|
||||
|
||||
Log.log(LogMessageType.RENDERING_LOADING) { "Unloading assets manager" }
|
||||
connection.assetsManager.unload()
|
||||
Log.log(LogMessageType.RENDERING_LOADING) { "Rendering is fully prepared in ${stopwatch.totalTime()}" }
|
||||
initialized = true
|
||||
latch.dec()
|
||||
|
@ -35,15 +35,17 @@ class WeightedBakedModel(
|
||||
totalWeight += weight
|
||||
}
|
||||
|
||||
check(totalWeight > 0) { "Weight must be >= 1" }
|
||||
this.totalWeight = totalWeight
|
||||
}
|
||||
|
||||
override fun getTouchingFaceProperties(random: Random, direction: Directions): Array<AbstractFaceProperties> {
|
||||
return getModel(random).getTouchingFaceProperties(random, direction)
|
||||
return getModel(random)?.getTouchingFaceProperties(random, direction) ?: arrayOf()
|
||||
}
|
||||
|
||||
private fun getModel(random: Random): BakedBlockModel {
|
||||
private fun getModel(random: Random): BakedBlockModel? {
|
||||
if (models.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
var weightLeft = abs(random.nextLong() % totalWeight)
|
||||
|
||||
for ((model, weight) in models) {
|
||||
@ -57,12 +59,12 @@ class WeightedBakedModel(
|
||||
}
|
||||
|
||||
override fun singleRender(position: Vec3i, mesh: WorldMesh, random: Random, blockState: BlockState, neighbours: Array<BlockState?>, light: ByteArray, ambientLight: FloatArray, tints: IntArray?): Boolean {
|
||||
return getModel(random).singleRender(position, mesh, random, blockState, neighbours, light, ambientLight, tints)
|
||||
return getModel(random)?.singleRender(position, mesh, random, blockState, neighbours, light, ambientLight, tints) ?: false
|
||||
}
|
||||
|
||||
override fun getParticleTexture(random: Random, blockPosition: Vec3i): AbstractTexture? {
|
||||
random.setSeed(VecUtil.generatePositionHash(blockPosition.x, blockPosition.y, blockPosition.z))
|
||||
return getModel(random).getParticleTexture(random, blockPosition)
|
||||
return getModel(random)?.getParticleTexture(random, blockPosition)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,7 +45,10 @@ class SoundData(
|
||||
companion object {
|
||||
|
||||
operator fun invoke(assetsManager: AssetsManager, sound: Sound): SoundData {
|
||||
val buffer = ByteBuffer.wrap(assetsManager[sound.path].readAllBytes())
|
||||
val vorbisData = assetsManager[sound.path].readAllBytes()
|
||||
val buffer = BufferUtils.createByteBuffer(vorbisData.size)
|
||||
buffer.put(vorbisData)
|
||||
buffer.rewind()
|
||||
|
||||
val error = BufferUtils.createIntBuffer(1)
|
||||
val vorbis = stb_vorbis_open_memory(buffer, error, null)
|
||||
@ -73,7 +76,7 @@ class SoundData(
|
||||
channels = channels,
|
||||
sampleRate = sampleRate,
|
||||
samplesLength = samplesLength,
|
||||
sampleSeconds = sampleSeconds
|
||||
sampleSeconds = sampleSeconds,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -32,11 +32,13 @@ data class SoundType(
|
||||
totalWeight += sound.weight
|
||||
}
|
||||
|
||||
check(totalWeight >= 1) { "Weight must be >= 1" }
|
||||
this.totalWeight = totalWeight
|
||||
}
|
||||
|
||||
fun getSound(random: Random): Sound {
|
||||
fun getSound(random: Random): Sound? {
|
||||
if (sounds.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
var weightLeft = abs(random.nextLong() % totalWeight)
|
||||
|
||||
for (sound in sounds) {
|
||||
|
@ -204,6 +204,7 @@ class PlayConnection(
|
||||
if (this::randomTickTask.isInitialized) {
|
||||
TimeWorker.removeTask(randomTickTask)
|
||||
}
|
||||
assetsManager.unload()
|
||||
state = PlayConnectionStates.DISCONNECTED
|
||||
ACTIVE_CONNECTIONS -= this
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user