flutter-plugins
flutter-plugins copied to clipboard
[desktop_multi_window v0.2.0] Invalid memory access upon app close
Upon closing app, there are various fatal memory access errors
Reproduce Steps
Steps to reproduce the behavior:
- Open an app with desktop_multi_window v0.2.0
- Close the app
- See crash logs (e.g.: Sentry Native or debug locally with Visual Studio)
Expected behavior
Upon closing app, no memory access violations should occur
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
Crash log dumps 0a27306d99e04b12ab0dc12b2e052135-symbolicated.txt 598f75b601014f48bd7a8f52d1ca6bc6-symbolicated.txt 51bef4fe07e04eb795279e3a6c32e8fc-symbolicated.txt a9343bc9a4a840cba5d26cea13bda751-symbolicated.txt b344426997b44e809894e49c6545b62f-symbolicated.txt
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.