flutter-plugins icon indicating copy to clipboard operation
flutter-plugins copied to clipboard

[desktop_multi_window v0.2.0] Invalid memory access upon app close

Open isaacy13 opened this issue 1 year ago • 1 comments

Upon closing app, there are various fatal memory access errors

Reproduce Steps

Steps to reproduce the behavior:

  1. Open an app with desktop_multi_window v0.2.0
  2. Close the app
  3. See crash logs (e.g.: Sentry Native or debug locally with Visual Studio)

Expected behavior

Upon closing app, no memory access violations should occur

image image

Version (please complete the following information):

  • Flutter Version: v3.19.3
  • OS: Windows
  • plugin: [desktop_multi_window v0.2.0]
Errors occur in C++ library and are not caught by Flutter

Can debug locally with Visual Studio by:
- Open Task Manager
- Right click app
- Debug
- New instance of Visual Studio
Seems like desktop_multi_window objects are trying to be used after Flutter app is closed & memory is deallocated

Challenge might be making sure all objects are destructed before Flutter app is closed

Commenting out WindowChannel destructor code seems to resolve memory access errors, but was hoping for a better solution
Note: repro steps only require main window to be created (and registered) -- no creation of subwindows required to reproduce issue

isaacy13 avatar May 20 '24 16:05 isaacy13

Apologies for forgetting to update this thread. Was a long while ago, but:

Likely root cause is Flutter upgrade broke multi-window functionality

  • closing new windows too many times -> app crash
  • closing app gives this memory access error

Workaround: https://github.com/MixinNetwork/flutter-plugins/issues/363#issuecomment-2585053947

In the time that I last posted, smarter people have reported an RCA

Per this thread https://github.com/flutter/flutter/issues/155685, this [MR](https://github.com/flutter/engine/pull/49954/files#diff-6fb5dee70153936fa0a06844e04a5bddbf779750e4670292b8f77eaae36c52bcR68) is root cause of crashing

Will shamelessly admit I just downgraded to Flutter v3.16.8 / Dart 3.2.5 and downgraded the associated packages

This resolved all crashing
Merged into Flutter on 1/23/2024, so just picked the [Flutter release](https://docs.flutter.dev/release/archive) before it (v3.16.8)
If you don't want to use an old Flutter version, according to others, you can attempt to patch your current Flutter version by:

reverting changes in this [MR](https://github.com/flutter/engine/pull/49954/files#diff-6fb5dee70153936fa0a06844e04a5bddbf779750e4670292b8f77eaae36c52bcR68)
OR

patching with https://github.com/flutter/flutter/issues/155685#issuecomment-2430293157
Have not tested any of these and personally wouldn't recommend it unless you have a good reason, as I imagine further debugging may be a headache

Will have to do it eventually, but that's a future me problem. Hopefully there's a better solution in the future

Relevant threads (might be more, these are old ones I found)

  • https://github.com/flutter/flutter/issues/155685
  • https://github.com/MixinNetwork/flutter-plugins/issues/363
  • https://github.com/MixinNetwork/flutter-plugins/issues/352

Future: I read somewhere (a while back) that said teams at Canonical are working on Flutter multi-window support. Can probably google it, but afaik this issue still stands.

isaacy13 avatar Jul 14 '25 00:07 isaacy13