From 370c0b7fc82305df0ddaf9ed7c40447454a2c39a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 23 Nov 2025 03:38:12 +0000 Subject: [PATCH 1/2] Initial plan From 46300146a11f736928a6020d5ce947a0ebe256db Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 23 Nov 2025 03:40:31 +0000 Subject: [PATCH 2/2] Combine nested if statements in WorldFocusedHandler Co-authored-by: nalathethird <36301692+nalathethird@users.noreply.github.com> --- bHapticsManager/bHapticsManager.cs | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/bHapticsManager/bHapticsManager.cs b/bHapticsManager/bHapticsManager.cs index c92cbc7..345dae9 100644 --- a/bHapticsManager/bHapticsManager.cs +++ b/bHapticsManager/bHapticsManager.cs @@ -127,24 +127,21 @@ public override void OnEngineInit() void WorldFocusedHandler(World world) { - if (world != null) + // Check if initialization is needed and atomically set _initialized to true + if (world != null && !Interlocked.CompareExchange(ref _initialized, true, false)) { - // Check if initialization is needed and atomically set _initialized to true - if (!Interlocked.CompareExchange(ref _initialized, true, false)) + try { - try - { - world.RunSynchronously(() => InitializeHaptics()); - // Unsubscribe from the event after first successful initialization - engine.WorldManager.WorldFocused -= WorldFocusedHandler; - ResoniteMod.Debug("WorldFocused event handler unsubscribed after initialization"); - } - catch (Exception ex) - { - Error($"Failed to initialize haptics on world focus: {ex}"); - // Reset _initialized to allow retry on next world focus - Interlocked.Exchange(ref _initialized, false); - } + world.RunSynchronously(() => InitializeHaptics()); + // Unsubscribe from the event after first successful initialization + engine.WorldManager.WorldFocused -= WorldFocusedHandler; + ResoniteMod.Debug("WorldFocused event handler unsubscribed after initialization"); + } + catch (Exception ex) + { + Error($"Failed to initialize haptics on world focus: {ex}"); + // Reset _initialized to allow retry on next world focus + Interlocked.Exchange(ref _initialized, false); } } }