Skip to content

fix(windows): refactor static globals to instance members to support …#1970

Open
idcpj wants to merge 1 commit intobluefireteam:mainfrom
idcpj:main
Open

fix(windows): refactor static globals to instance members to support …#1970
idcpj wants to merge 1 commit intobluefireteam:mainfrom
idcpj:main

Conversation

@idcpj
Copy link

@idcpj idcpj commented Jan 27, 2026

fix(windows): support multi-engine and fix crashes in multi-window environments

Description

Previously, AudioplayersWindowsPlugin utilized static inline global variables for the MethodChannel and EventStreamHandler. In multi-window scenarios (e.g., using desktop_multi_window), where multiple Flutter Engines are initialized, these static pointers were overwritten by the most recently opened window. This caused the plugin state of previous windows to become corrupted, leading to crashes and inconsistent behavior.

This PR refactors the plugin to move these globals into instance members. This ensures:

  • Each Engine instance maintains its own independent MethodChannel and EventStreamHandler.
  • Plugin states are completely isolated across different windows.
  • Memory safety is improved by preventing the overwriting of global static pointers.

Checklist

  • The title of my PR starts with a Conventional Commit prefix (fix:, feat:, refactor:, docs:, chore:, test:, ci: etc).
  • I have read the Contributor Guide and followed the process outlined for submitting PRs.
  • I have updated/added tests for ALL new/updated/fixed functionality. (N/A for architectural refactor)
  • I have updated/added relevant documentation and added dartdoc comments with ///, where necessary.
  • I have updated/added relevant examples in example.

Breaking Change

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

Related Issues

Resolves crashes in multi-window/multi-engine environments on Windows.

…multiple windows

- Replaced all `static inline` global variables with instance members in `AudioplayersWindowsPlugin`.
- Ensured each Engine instance possesses its own independent `MethodChannel` and `EventStreamHandler`.
- Fixed crashes occurring when opening a second window due to global static pointer overwriting.
- Isolated plugin state across different windows to prevent interference.
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.

1 participant