From 3f307605cc5bd6e2e1ce034a6aae70b77e4a4da2 Mon Sep 17 00:00:00 2001 From: Butterscotch! Date: Fri, 15 Sep 2023 22:37:46 -0400 Subject: [PATCH] Android ByteBuffer and Color fixes (#842) --- .../android/src/main/java/java/awt/Color.java | 4 ++++ .../main/java/dev/slimevr/osc/OSCRouter.java | 7 ++----- .../main/java/dev/slimevr/osc/OSCStatic.java | 18 ------------------ .../main/java/dev/slimevr/osc/VMCHandler.java | 10 ++-------- .../main/java/dev/slimevr/osc/VRCOSCHandler.kt | 10 ++-------- .../tracking/trackers/udp/UDPProtocolParser.kt | 3 ++- 6 files changed, 12 insertions(+), 40 deletions(-) create mode 100644 server/android/src/main/java/java/awt/Color.java delete mode 100644 server/core/src/main/java/dev/slimevr/osc/OSCStatic.java diff --git a/server/android/src/main/java/java/awt/Color.java b/server/android/src/main/java/java/awt/Color.java new file mode 100644 index 0000000000..e1d92799f6 --- /dev/null +++ b/server/android/src/main/java/java/awt/Color.java @@ -0,0 +1,4 @@ +package java.awt; + +public class Color { +} diff --git a/server/core/src/main/java/dev/slimevr/osc/OSCRouter.java b/server/core/src/main/java/dev/slimevr/osc/OSCRouter.java index dc98207c64..0621dfa2b8 100644 --- a/server/core/src/main/java/dev/slimevr/osc/OSCRouter.java +++ b/server/core/src/main/java/dev/slimevr/osc/OSCRouter.java @@ -72,7 +72,7 @@ public void refreshSettings(boolean refreshHandlersSettings) { // Else, create our own OSC receiver if (oscReceiver == null) { try { - oscReceiver = new OSCPortIn(OSCStatic.serializer, portIn); + oscReceiver = new OSCPortIn(portIn); if (lastPortIn != portIn || !wasListening) { LogManager.info("[OSCRouter] Listening to port " + portIn); } @@ -114,10 +114,7 @@ public void refreshSettings(boolean refreshHandlersSettings) { // Else, create our own OSC sender if (oscSender == null) { try { - oscSender = new OSCPortOut( - OSCStatic.serializer, - new InetSocketAddress(address, portOut) - ); + oscSender = new OSCPortOut(new InetSocketAddress(address, portOut)); if ((lastPortOut != portOut && lastAddress != address) || !wasConnected) { LogManager .info( diff --git a/server/core/src/main/java/dev/slimevr/osc/OSCStatic.java b/server/core/src/main/java/dev/slimevr/osc/OSCStatic.java deleted file mode 100644 index 797a566f06..0000000000 --- a/server/core/src/main/java/dev/slimevr/osc/OSCStatic.java +++ /dev/null @@ -1,18 +0,0 @@ -package dev.slimevr.osc; - -import com.illposed.osc.OSCSerializerAndParserBuilder; - - -public class OSCStatic { - public static OSCSerializerAndParserBuilder serializer; - - static { - // Really hacky workaround for getting the OSC library to work on - // Android (Removes reference to java.awt.Color) - OSCSerializerAndParserBuilder serializer = new OSCSerializerAndParserBuilder(); - serializer.setUsingDefaultHandlers(true); - serializer.unregisterArgumentHandler('r'); - - OSCStatic.serializer = serializer; - } -} diff --git a/server/core/src/main/java/dev/slimevr/osc/VMCHandler.java b/server/core/src/main/java/dev/slimevr/osc/VMCHandler.java index 6eb90001df..854cb8707f 100644 --- a/server/core/src/main/java/dev/slimevr/osc/VMCHandler.java +++ b/server/core/src/main/java/dev/slimevr/osc/VMCHandler.java @@ -93,10 +93,7 @@ public void refreshSettings(boolean refreshRouterSettings) { // Instantiates the OSC receiver try { int port = config.getPortIn(); - oscReceiver = new OSCPortIn( - OSCStatic.serializer, - port - ); + oscReceiver = new OSCPortIn(port); if (lastPortIn != port || !wasListening) { LogManager.info("[VMCHandler] Listening to port " + port); } @@ -130,10 +127,7 @@ public void refreshSettings(boolean refreshRouterSettings) { try { InetAddress address = InetAddress.getByName(config.getAddress()); int port = config.getPortOut(); - oscSender = new OSCPortOut( - OSCStatic.serializer, - new InetSocketAddress(address, port) - ); + oscSender = new OSCPortOut(new InetSocketAddress(address, port)); if ((lastPortOut != port && lastAddress != address) || !wasConnected) { LogManager .info( diff --git a/server/core/src/main/java/dev/slimevr/osc/VRCOSCHandler.kt b/server/core/src/main/java/dev/slimevr/osc/VRCOSCHandler.kt index e21b4dbdd2..08240fc112 100644 --- a/server/core/src/main/java/dev/slimevr/osc/VRCOSCHandler.kt +++ b/server/core/src/main/java/dev/slimevr/osc/VRCOSCHandler.kt @@ -99,10 +99,7 @@ class VRCOSCHandler( // Instantiates the OSC receiver try { val port = config.portIn - oscReceiver = OSCPortIn( - OSCStatic.serializer, - port - ) + oscReceiver = OSCPortIn(port) if (lastPortIn != port || !wasListening) { LogManager.info("[VRCOSCHandler] Listening to port $port") } @@ -142,10 +139,7 @@ class VRCOSCHandler( try { val address = InetAddress.getByName(config.address) val port = config.portOut - oscSender = OSCPortOut( - OSCStatic.serializer, - InetSocketAddress(address, port) - ) + oscSender = OSCPortOut(InetSocketAddress(address, port)) if (lastPortOut != port && lastAddress !== address || !wasConnected) { LogManager .info( diff --git a/server/core/src/main/java/dev/slimevr/tracking/trackers/udp/UDPProtocolParser.kt b/server/core/src/main/java/dev/slimevr/tracking/trackers/udp/UDPProtocolParser.kt index 9592a62874..c75e295497 100644 --- a/server/core/src/main/java/dev/slimevr/tracking/trackers/udp/UDPProtocolParser.kt +++ b/server/core/src/main/java/dev/slimevr/tracking/trackers/udp/UDPProtocolParser.kt @@ -25,7 +25,8 @@ class UDPProtocolParser { if (bundlePacketLen == 0) continue val bundlePacketStart = buf.position() - val bundleBuf = buf.slice(bundlePacketStart, bundlePacketLen) + val bundleBuf = buf.slice() + bundleBuf.limit(bundlePacketLen) val bundlePacketId = bundleBuf.int val newPacket = getNewPacket(bundlePacketId) newPacket?.let {