Skip to content

Commit

Permalink
Fix exceptions on Oculus
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoco007 committed Feb 3, 2020
1 parent ab4d947 commit 6baaf3a
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions Source/DynamicOpenVR.BeatSaber/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public class Plugin : IBeatSaberPlugin

private HarmonyInstance _harmonyInstance;

private readonly HashSet<EVREventType> pauseEvents = new HashSet<EVREventType>(new [] { EVREventType.VREvent_InputFocusCaptured, EVREventType.VREvent_DashboardActivated, EVREventType.VREvent_OverlayShown });
private readonly HashSet<EVREventType> _pauseEvents = new HashSet<EVREventType>(new [] { EVREventType.VREvent_InputFocusCaptured, EVREventType.VREvent_DashboardActivated, EVREventType.VREvent_OverlayShown });

private bool _initialized;

public void Init(Logger logger)
{
Expand All @@ -68,6 +70,8 @@ public void OnApplicationStart()
AddManifestToSteamConfig();
RegisterActionSet();
ApplyHarmonyPatches();

_initialized = true;
}
catch (Exception ex)
{
Expand All @@ -79,13 +83,13 @@ public void OnApplicationStart()
public void OnApplicationQuit()
{
// not really necessary here, just following good practices
leftTriggerValue.Dispose();
rightTriggerValue.Dispose();
menu.Dispose();
leftSlice.Dispose();
rightSlice.Dispose();
leftHandPose.Dispose();
rightHandPose.Dispose();
leftTriggerValue?.Dispose();
rightTriggerValue?.Dispose();
menu?.Dispose();
leftSlice?.Dispose();
rightSlice?.Dispose();
leftHandPose?.Dispose();
rightHandPose?.Dispose();
}

private void AddManifestToSteamConfig()
Expand Down Expand Up @@ -248,10 +252,13 @@ public void OnSceneUnloaded(Scene scene) { }

public void OnUpdate()
{
VREvent_t evt = default;
if (OpenVR.System.PollNextEvent(ref evt, (uint)Marshal.SizeOf(typeof(VREvent_t))) && pauseEvents.Contains((EVREventType) evt.eventType))
if (_initialized)
{
Resources.FindObjectsOfTypeAll<PauseController>().FirstOrDefault()?.Pause();
VREvent_t evt = default;
if (OpenVR.System.PollNextEvent(ref evt, (uint)Marshal.SizeOf(typeof(VREvent_t))) && _pauseEvents.Contains((EVREventType) evt.eventType))
{
Resources.FindObjectsOfTypeAll<PauseController>().FirstOrDefault()?.Pause();
}
}
}
}
Expand Down

0 comments on commit 6baaf3a

Please sign in to comment.