Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 23, 2025

The Initialize() method checked _isInitialized without synchronization, allowing concurrent threads to pass the guard simultaneously and attempt multiple initializations.

Changes

  • Added _initializeLock to serialize initialization and shutdown
  • Wrapped Initialize() method body in lock to prevent concurrent initialization attempts
  • Protected _isInitialized write in Shutdown() with same lock
public static bool Initialize() {
    lock (_initializeLock) {
        if (_isInitialized) {
            ResoniteMod.Warn("Already initialized - skipping duplicate connection");
            return true;
        }
        
        // Connect to bHaptics Player
        bool connected = ModernBHaptics.bHapticsManager.Connect("Resonite", "Resonite", true, 10);
        // ...
        _isInitialized = true;
        return true;
    }
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: nalathethird <36301692+nalathethird@users.noreply.github.com>
Copilot AI changed the title [WIP] Update architecture for bHapticsManager based on review feedback Fix race condition in BHapticsConnection.Initialize() Nov 23, 2025
Copilot AI requested a review from nalathethird November 23, 2025 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants