From cfef1645b7247031e40f310540528ff9f18f87f2 Mon Sep 17 00:00:00 2001 From: Apehum <36326454+Apehum@users.noreply.github.com> Date: Sun, 13 Oct 2024 06:30:08 +0800 Subject: [PATCH] fix: create new instance of source and player positions on each source packet send to avoid race conditions #422 --- .../voice/server/audio/source/VoiceServerEntitySource.kt | 6 ++---- .../voice/server/audio/source/VoiceServerPlayerSource.kt | 4 +--- .../voice/server/audio/source/VoiceServerProximitySource.kt | 4 ++-- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/server/common/src/main/kotlin/su/plo/voice/server/audio/source/VoiceServerEntitySource.kt b/server/common/src/main/kotlin/su/plo/voice/server/audio/source/VoiceServerEntitySource.kt index 73947c5d..0b8a6bd8 100644 --- a/server/common/src/main/kotlin/su/plo/voice/server/audio/source/VoiceServerEntitySource.kt +++ b/server/common/src/main/kotlin/su/plo/voice/server/audio/source/VoiceServerEntitySource.kt @@ -21,10 +21,8 @@ class VoiceServerEntitySource( ) : VoiceServerProximitySource(voiceServer, addon, UUID.randomUUID(), line, decoderInfo, stereo), ServerEntitySource { - override val position: ServerPos3d = entity.getServerPosition() - get() { - return entity.getServerPosition(field) - } + override val position: ServerPos3d + get() = entity.getServerPosition() override val sourceInfo: EntitySourceInfo get() = EntitySourceInfo( diff --git a/server/common/src/main/kotlin/su/plo/voice/server/audio/source/VoiceServerPlayerSource.kt b/server/common/src/main/kotlin/su/plo/voice/server/audio/source/VoiceServerPlayerSource.kt index fcffc870..098423a6 100644 --- a/server/common/src/main/kotlin/su/plo/voice/server/audio/source/VoiceServerPlayerSource.kt +++ b/server/common/src/main/kotlin/su/plo/voice/server/audio/source/VoiceServerPlayerSource.kt @@ -21,10 +21,8 @@ class VoiceServerPlayerSource( ) : VoiceServerProximitySource(voiceServer, addon, UUID.randomUUID(), line, decoderInfo, stereo), ServerPlayerSource { - private val playerPosition = ServerPos3d() - override val position: ServerPos3d - get() = player.instance.getServerPosition(playerPosition) + get() = player.instance.getServerPosition() override val sourceInfo: PlayerSourceInfo get() = PlayerSourceInfo( diff --git a/server/common/src/main/kotlin/su/plo/voice/server/audio/source/VoiceServerProximitySource.kt b/server/common/src/main/kotlin/su/plo/voice/server/audio/source/VoiceServerProximitySource.kt index c5852158..d4a769ae 100644 --- a/server/common/src/main/kotlin/su/plo/voice/server/audio/source/VoiceServerProximitySource.kt +++ b/server/common/src/main/kotlin/su/plo/voice/server/audio/source/VoiceServerProximitySource.kt @@ -27,8 +27,6 @@ abstract class VoiceServerProximitySource( stereo: Boolean ) : BaseServerAudioSource(addon, id, serverSourceLine, decoderInfo, stereo), ServerProximitySource { - private val playerPosition = ServerPos3d() - override var angle: Int = 0 get() = field set(value) { @@ -50,6 +48,7 @@ abstract class VoiceServerProximitySource( if (dirty.compareAndSet(true, false)) sendPacket(SourceInfoPacket(sourceInfo), listenersDistance.toShort()) + val playerPosition = ServerPos3d() val sourcePosition = position val distanceSquared = (listenersDistance * listenersDistance).toDouble() @@ -74,6 +73,7 @@ abstract class VoiceServerProximitySource( val listenersDistance = event.distance * DISTANCE_MULTIPLIER + val playerPosition = ServerPos3d() val sourcePosition = position val distanceSquared = (listenersDistance * listenersDistance).toDouble()