Skip to content

Commit 6baaf3a

Browse files
committed
Fix exceptions on Oculus
1 parent ab4d947 commit 6baaf3a

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

Source/DynamicOpenVR.BeatSaber/Plugin.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public class Plugin : IBeatSaberPlugin
4545

4646
private HarmonyInstance _harmonyInstance;
4747

48-
private readonly HashSet<EVREventType> pauseEvents = new HashSet<EVREventType>(new [] { EVREventType.VREvent_InputFocusCaptured, EVREventType.VREvent_DashboardActivated, EVREventType.VREvent_OverlayShown });
48+
private readonly HashSet<EVREventType> _pauseEvents = new HashSet<EVREventType>(new [] { EVREventType.VREvent_InputFocusCaptured, EVREventType.VREvent_DashboardActivated, EVREventType.VREvent_OverlayShown });
49+
50+
private bool _initialized;
4951

5052
public void Init(Logger logger)
5153
{
@@ -68,6 +70,8 @@ public void OnApplicationStart()
6870
AddManifestToSteamConfig();
6971
RegisterActionSet();
7072
ApplyHarmonyPatches();
73+
74+
_initialized = true;
7175
}
7276
catch (Exception ex)
7377
{
@@ -79,13 +83,13 @@ public void OnApplicationStart()
7983
public void OnApplicationQuit()
8084
{
8185
// not really necessary here, just following good practices
82-
leftTriggerValue.Dispose();
83-
rightTriggerValue.Dispose();
84-
menu.Dispose();
85-
leftSlice.Dispose();
86-
rightSlice.Dispose();
87-
leftHandPose.Dispose();
88-
rightHandPose.Dispose();
86+
leftTriggerValue?.Dispose();
87+
rightTriggerValue?.Dispose();
88+
menu?.Dispose();
89+
leftSlice?.Dispose();
90+
rightSlice?.Dispose();
91+
leftHandPose?.Dispose();
92+
rightHandPose?.Dispose();
8993
}
9094

9195
private void AddManifestToSteamConfig()
@@ -248,10 +252,13 @@ public void OnSceneUnloaded(Scene scene) { }
248252

249253
public void OnUpdate()
250254
{
251-
VREvent_t evt = default;
252-
if (OpenVR.System.PollNextEvent(ref evt, (uint)Marshal.SizeOf(typeof(VREvent_t))) && pauseEvents.Contains((EVREventType) evt.eventType))
255+
if (_initialized)
253256
{
254-
Resources.FindObjectsOfTypeAll<PauseController>().FirstOrDefault()?.Pause();
257+
VREvent_t evt = default;
258+
if (OpenVR.System.PollNextEvent(ref evt, (uint)Marshal.SizeOf(typeof(VREvent_t))) && _pauseEvents.Contains((EVREventType) evt.eventType))
259+
{
260+
Resources.FindObjectsOfTypeAll<PauseController>().FirstOrDefault()?.Pause();
261+
}
255262
}
256263
}
257264
}

0 commit comments

Comments
 (0)