From 66dc7440a109d36aa999390f06c357abc3c7399b Mon Sep 17 00:00:00 2001 From: hammy275 Date: Sun, 14 Jan 2024 11:21:29 -0500 Subject: [PATCH] Hopefully Fixed Hotswap Crashes + Version Bump --- .../java/net/blf02/vrapi/client/VRDataGrabber.java | 12 ++++++++++++ .../main/java/net/blf02/vrapi/common/Constants.java | 2 +- gradle.properties | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/net/blf02/vrapi/client/VRDataGrabber.java b/common/src/main/java/net/blf02/vrapi/client/VRDataGrabber.java index 61c6353..c22df75 100644 --- a/common/src/main/java/net/blf02/vrapi/client/VRDataGrabber.java +++ b/common/src/main/java/net/blf02/vrapi/client/VRDataGrabber.java @@ -124,6 +124,10 @@ public static VRPlayer getVRPlayer(PlayerType type) { try { Object vrPlayerRaw = VRPlayer_GET.invoke(null); // Get our "VRPlayer" from Vivecraft} + // In case we switch out of VR after the !inVR() check + if (vrPlayerRaw == null) { + return null; + } Object vrDataRaw; // Get the "VRData" from Vivecraft switch (type) { @@ -134,6 +138,11 @@ public static VRPlayer getVRPlayer(PlayerType type) { default -> vrDataRaw = VRPlayer_vrdata_world_post.get(vrPlayerRaw); // Covers POST and null } + // In case we switch out of VR after the !inVR() check + if (vrDataRaw == null) { + return null; + } + Object hmdDevicePoseRaw = VRData_hmd.get(vrDataRaw); // Get the VRDevicePose for the HMD Object c0DevicePoseRaw = VRData_c0.get(vrDataRaw); @@ -173,6 +182,9 @@ public static VRPlayer getVRPlayer(PlayerType type) { // We shouldn't error here, as we know these fields and methods exist due to getField() and getMethod() // combined with having access to Vivecraft's codebase on GitHub throw new RuntimeException("Could not obtain data from Vivecraft! Something has gone horribly wrong."); + } catch (NullPointerException ignored) { + // In case something returns null after the inVR() check due to hotswap. + return null; } } diff --git a/common/src/main/java/net/blf02/vrapi/common/Constants.java b/common/src/main/java/net/blf02/vrapi/common/Constants.java index 8c64789..9598c37 100644 --- a/common/src/main/java/net/blf02/vrapi/common/Constants.java +++ b/common/src/main/java/net/blf02/vrapi/common/Constants.java @@ -3,7 +3,7 @@ public class Constants { // Version {major, minor, patch} - public static final int[] version = new int[]{3, 0, 6}; + public static final int[] version = new int[]{3, 0, 7}; // Debugging public static final boolean doDebugging = false; diff --git a/gradle.properties b/gradle.properties index ad33b7d..26682f0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ minecraft_version=1.19.2 enabled_platforms=quilt,fabric,forge archives_base_name=vrapi -mod_version=3.0.6 +mod_version=3.0.7 maven_group=net.blf02.vrapi architectury_version=6.2.43