Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] msvcp140.dll crashes and closes the app on windows 11 when playing sound #272

Closed
Hamid313-coder opened this issue Jun 13, 2024 · 6 comments

Comments

@Hamid313-coder
Copy link

Hamid313-coder commented Jun 13, 2024

When I build my flutter windows app which has "audio_players" and "video_player" on windows 11 using msix, it crashes and closes the app when I play sound or play video.
I checked using "Event Viewer". it says the fault is from msvcp140.dll file.
when I replace that .dll file with file which is located in "visual studio" folder. it works fine.

@insertjokehere
Copy link

This issue has eaten the last four days of my life, so bare with me if this explanation takes a bit.

  1. When building a VC++ app (like all Flutter apps) you need to link against the VC++ runtime, and you include a version of the libraries with your app when you distribute it to end users
  2. Microsoft requires that "the Redistributable version must be at least as new as the latest toolset used by any app component"
  3. This library includes an ancient version of the VC++ runtime, and bundles them into the generated installer:

msix/lib/src/assets.dart

Lines 263 to 270 in 2faab7e

/// Copy the VC libs files (msvcp140.dll, vcruntime140.dll, vcruntime140_1.dll)
Future<void> copyVCLibsFiles() async {
_logger.trace('copying VC libraries');
await Directory(
p.join(_config.msixAssetsPath, 'VCLibs', _config.architecture))
.copyDirectory(Directory(_config.buildFilesFolder));
}

  1. Somehow, this has been working without major issues for the last few years - except that recently, Microsoft released an update to Visual Studio 2022 that fixed an issue in mutex from the VC++ runtime, but which requires that you follow the "at least as new as the latest toolset" rule. They even note in the changelog that

Programs that aren't following the documented restrictions on binary compatibility may encounter null dereferences in mutex machinery"

  1. Github have updated their windows and windows-latest runner images to use the newest Visual Studio, which has caused a bit of chaos generally: New unexpected build failures on 20240603.1.0 actions/runner-images#10004

  2. The upshot of this is that if any of the Flutter plugins you are using use mutex, and you are building the app on a machine that has VS2022 17.10 or newer, and your users don't already have VC++ runtime 14.40.33810.0 or newer, your app will crash as soon as the plugin tries to use the mutex

As far as fixes are concerned, I'm not sure the best approach here. The current approach of bundling an static version of the VC++ redist with this module is fundamentally broken, but I acknowledge that we need some kind of fix to make it easier to bundle the required libraries with the installer.

I'm still working through a proper fix for my app, and will report back once I have one.

@insertjokehere
Copy link

OK - I have a workaround that Works For Me:

I'll work on getting a proper PR up and getting my package onto pub.dev - for now, you'll need to use the packages from git. Update your pubspec like:

dependencies:
  msvcredist:
    git:
      url: https://github.com/insertjokehere/flutter_msvcredist.git
      ref: main

dev_dependencies:
  msix:
    git:
      url: https://github.com/insertjokehere/msix.git
      ref: msvc_redist

@PeterNjeim
Copy link

PeterNjeim commented Jun 30, 2024

Thank you for discovering the problem. I noticed that my local build worked fine but production build in GitHub Actions had the crash, and I analyzed the difference between the MSIX files and saw that they had a different DLL for a WebRTC plugin I use (which in an older version, immediately initiated an audio connection (still don't know why it gets a different DLL for it, but that's another issue)).

This made the app crash on startup, only in the production build lol. I also noticed that it had the old msvcp140.dll, vcruntime140.dll, and vcruntime140_1.dll. I noticed that replacing them with the new versions fixed it (or leaving them and instead changing the DLL of the WebRTC plugin). I was going to fix it by changing the DLL's manually, but I like the closure of knowing that it was audio (mutex) specifically that was causing the issue

@UdaraAlwis
Copy link

OK - I have a workaround that Works For Me:

I'll work on getting a proper PR up and getting my package onto pub.dev - for now, you'll need to use the packages from git. Update your pubspec like:

dependencies:
  msvcredist:
    git:
      url: https://github.com/insertjokehere/flutter_msvcredist.git
      ref: main

dev_dependencies:
  msix:
    git:
      url: https://github.com/insertjokehere/msix.git
      ref: msvc_redist

Thank you for posting this workaround! We had a similar issue on Windows 11 where our Flutter Windows app crashing whenever we accessed the webcam through the camera_windows library. We're also using this msix package for bundling our Windows app with flutter as well.
This workaround helped us resolve that crash! I hope they release a permanent fix soon.

@venky9885
Copy link

Error find from Event Viewer
Faulting module name: MSVCP140.dll, version: 14.26.28804.1, time stamp: 0x5e9b29e5
Exception code: 0xc0000005

@YehudaKremer
Copy link
Owner

@riccardo-lomazzi fix it #273 (version 3.16.8)
sorry for the late response.

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

No branches or pull requests

6 participants