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

[desktop_multi_window] App is crashing while closing windows

Open lukasz-lukasz-lukasz opened this issue 1 year ago β€’ 19 comments

I encounter crashes in my app and in the plugin example app - the problem is random, sometimes easy to replicate but sometimes it can take a long time to reproduce it.

The app simply crashes from time to time when closing their windows.

Reproduce Steps

  1. build the example app(desktop_multi_window/example/lib/main.dart) from https://pub.dev/packages/desktop_multi_window plugin.
  2. create a set of windows e.g. 15 windows - by clicking on the "Create a new World!" button
  3. start closing them immediately by fast-clicking on the "x" window button
  4. repeat the above steps until the app crashes

https://github.com/user-attachments/assets/4f3f61c6-99e0-4b0b-8ac8-d13e955d8e48

Sometimes creating 3-4 sets of windows is enough to see the problem.. but sometimes you can create and close hundreds of windows without the issue.

This problem may seem rare because it's not easy to reproduce, but I have several instances of this happening throughout an 8-hour workday, so it's problematic.

Expected behavior

There is no crash inside the flutter code. The application is stable while creating and closing windows.

Actual results

The app is crashing randomly and is unstable. There is no way to handle that issue in the app code. The issue makes the multi-window app unusable.

Version (please complete the following information):

  • Flutter Version: [3.22.3]
  • OS: [Windows]
  • plugin: [desktop_multi_window 0.2.0]
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.22.3, on Microsoft Windows [Version 10.0.19045.4651], locale pl-PL)
[√] Windows Version (Installed version of Windows is version 10 or higher)      
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.3)  
[√] Android Studio (version 2023.3)
[√] VS Code (version 1.91.1)
[√] Connected device (3 available)
[√] Network resources

β€’ No issues found!

Additional context

Crash call stack:

 	flutter_windows.dll!rx::Framebuffer11::markAttachmentsDirty(const gl::Context * context) Line 80	C++
 	flutter_windows.dll!rx::StateManager11::updateState(const gl::Context * context, gl::PrimitiveMode mode, int firstVertex, int vertexOrIndexCount, gl::DrawElementsType indexTypeOrInvalid, const void * indices, int instanceCount, int baseVertex, unsigned int baseInstance, bool promoteDynamic) Line 2255	C++
 	[Inline Frame] flutter_windows.dll!rx::Context11::drawElementsImpl(const gl::Context * context, gl::PrimitiveMode mode, int indexCount, gl::DrawElementsType indexType, const void * indices, int instanceCount, int baseVertex, unsigned int baseInstance, bool promoteDynamic, bool isInstancedDraw) Line 328	C++
 	flutter_windows.dll!rx::Context11::drawRangeElements(const gl::Context * context, gl::PrimitiveMode mode, unsigned int count, unsigned int type, int indices, gl::DrawElementsType) Line 406	C++
 	flutter_windows.dll!gl::Context::drawRangeElements(gl::PrimitiveMode mode, unsigned int start, unsigned int end, int count, gl::DrawElementsType type, const void * indices) Line 2899	C++
 	flutter_windows.dll!GL_DrawRangeElements(unsigned int mode, unsigned int start, unsigned int end, int count, unsigned int type, const void * indices) Line 850	C++
 	[Inline Frame] flutter_windows.dll!GrGLFunction<void (unsigned int, unsigned int, unsigned int, unsigned int, int, const char *)>::GrGLFunction::<lambda_1>::operator()(const void * buf, unsigned int args, unsigned int args, unsigned int args, unsigned int args, int args, const char * args) Line 271	C++
 	flutter_windows.dll!GrGLFunction<void (unsigned int, unsigned int, unsigned int, unsigned int, int, const char *)>::GrGLFunction::<lambda_1>::__invoke(const void * buf, unsigned int args, unsigned int args, unsigned int args, unsigned int args, int args, const char * args) Line 270	C++
 	flutter_windows.dll!GrGLOpsRenderPass::onDrawIndexed(int indexCount, int baseIndex, unsigned short minIndexValue, unsigned short maxIndexValue, int baseVertex) Line 216	C++
 	[Inline Frame] flutter_windows.dll!GrOpsRenderPass::drawIndexed(int indexCount, int baseIndex, unsigned short minIndexValue, unsigned short maxIndexValue, int baseVertex) Line 246	C++
 	flutter_windows.dll!GrOpsRenderPass::drawIndexPattern(int patternIndexCount, int patternRepeatCount, int maxPatternRepetitionsInIndexBuffer, int patternVertexCount, int baseVertex) Line 340	C++
 	[Inline Frame] flutter_windows.dll!GrOpFlushState::drawIndexPattern(int patternIndexCount, int patternRepeatCount, int maxPatternRepetitionsInIndexBuffer, int patternVertexCount, int baseVertex) Line 292	C++
 	flutter_windows.dll!GrOpFlushState::drawMesh(const GrSimpleMesh & mesh) Line 249	C++
 	flutter_windows.dll!GrOpFlushState::executeDrawsAndUploadsForMeshDrawOp(const GrOp * op, const SkRect & chainBounds, const GrPipeline * pipeline, const GrUserStencilSettings * userStencilSettings) Line 75	C++
 	flutter_windows.dll!skgpu::ganesh::AtlasTextOp::onExecute(GrOpFlushState * flushState, const SkRect & chainBounds) Line 376	C++
 	flutter_windows.dll!GrOp::execute(GrOpFlushState * state, const SkRect & chainBounds) Line 193	C++
 	flutter_windows.dll!skgpu::ganesh::OpsTask::onExecute(GrOpFlushState * flushState) Line 649	C++
 	[Inline Frame] flutter_windows.dll!GrRenderTask::execute(GrOpFlushState * flushState) Line 42	C++
 	flutter_windows.dll!GrDrawingManager::executeRenderTasks(GrOpFlushState * flushState) Line 272	C++
 	flutter_windows.dll!GrDrawingManager::flush(SkSpan<GrSurfaceProxy *> proxies, SkSurfaces::BackendSurfaceAccess access, const GrFlushInfo & info, const skgpu::MutableTextureState * newState) Line 193	C++
 	flutter_windows.dll!GrDrawingManager::flushSurfaces(SkSpan<GrSurfaceProxy *> proxies, SkSurfaces::BackendSurfaceAccess access, const GrFlushInfo & info, const skgpu::MutableTextureState * newState) Line 521	C++
 	flutter_windows.dll!GrDirectContext::flush(const GrFlushInfo & info) Line 444	C++
 	[Inline Frame] flutter_windows.dll!GrDirectContext::flushAndSubmit(GrSyncCpu sync) Line 333	C++
 	flutter_windows.dll!flutter::DlSkCanvasAdapter::Flush() Line 350	C++
 	flutter_windows.dll!flutter::EmbedderExternalView::Render(const flutter::EmbedderRenderTarget & render_target, bool clear_surface) Line 136	C++
 	[Inline Frame] flutter_windows.dll!flutter::`anonymous namespace'::Layer::RenderFlutterContents() Line 251	C++
 	[Inline Frame] flutter_windows.dll!flutter::`anonymous namespace'::LayerBuilder::Render() Line 323	C++
 	flutter_windows.dll!flutter::EmbedderExternalViewEmbedder::SubmitFlutterView(__int64 flutter_view_id, GrDirectContext * context, const std::shared_ptr<impeller::AiksContext> & aiks_context, std::unique_ptr<flutter::SurfaceFrame,std::default_delete<flutter::SurfaceFrame>> frame) Line 466	C++
 	flutter_windows.dll!flutter::Rasterizer::DrawToSurfaceUnsafe(__int64 view_id, flutter::LayerTree & layer_tree, float device_pixel_ratio, std::optional<fml::TimePoint> presentation_time) Line 754	C++
 	flutter_windows.dll!flutter::Rasterizer::DrawToSurfacesUnsafe(flutter::FrameTimingsRecorder & frame_timings_recorder, std::vector<std::unique_ptr<flutter::LayerTreeTask,std::default_delete<flutter::LayerTreeTask>>,std::allocator<std::unique_ptr<flutter::LayerTreeTask,std::default_delete<flutter::LayerTreeTask>>>> tasks) Line 623	C++
 	flutter_windows.dll!flutter::Rasterizer::DrawToSurfaces(flutter::FrameTimingsRecorder & frame_timings_recorder, std::vector<std::unique_ptr<flutter::LayerTreeTask,std::default_delete<flutter::LayerTreeTask>>,std::allocator<std::unique_ptr<flutter::LayerTreeTask,std::default_delete<flutter::LayerTreeTask>>>> tasks) Line 551	C++
 	flutter_windows.dll!flutter::Rasterizer::DoDraw(std::unique_ptr<flutter::FrameTimingsRecorder,std::default_delete<flutter::FrameTimingsRecorder>> frame_timings_recorder, std::vector<std::unique_ptr<flutter::LayerTreeTask,std::default_delete<flutter::LayerTreeTask>>,std::allocator<std::unique_ptr<flutter::LayerTreeTask,std::default_delete<flutter::LayerTreeTask>>>> tasks) Line 461	C++
 	[Inline Frame] flutter_windows.dll!flutter::Rasterizer::Draw::<lambda_1>::operator()(std::unique_ptr<flutter::FrameItem,std::default_delete<flutter::FrameItem>>) Line 251	C++
 	[Inline Frame] flutter_windows.dll!std::invoke(flutter::Rasterizer::Draw::<lambda_1> & _Obj, std::unique_ptr<flutter::FrameItem,std::default_delete<flutter::FrameItem>> && _Arg1) Line 1572	C++
 	[Inline Frame] flutter_windows.dll!std::_Invoker_ret<void>::_Call(flutter::Rasterizer::Draw::<lambda_1> & _Func, std::unique_ptr<flutter::FrameItem,std::default_delete<flutter::FrameItem>> && _Vals) Line 670	C++
 	flutter_windows.dll!std::_Func_impl_no_alloc<`lambda at ..\..\flutter\shell\common\rasterizer.cc:249:38',void,std::unique_ptr<flutter::FrameItem,std::default_delete<flutter::FrameItem>>>::_Do_call(std::unique_ptr<flutter::FrameItem,std::default_delete<flutter::FrameItem>> && _Args) Line 833	C++
 	flutter_windows.dll!std::_Func_class<void,std::unique_ptr<flutter::FrameItem,std::default_delete<flutter::FrameItem>>>::operator()(std::unique_ptr<flutter::FrameItem,std::default_delete<flutter::FrameItem>> _Args) Line 875	C++
 	flutter_windows.dll!flutter::Pipeline<flutter::FrameItem>::Consume(const std::function<void (std::unique_ptr<flutter::FrameItem,std::default_delete<flutter::FrameItem>>)> & consumer) Line 205	C++
 	flutter_windows.dll!flutter::Rasterizer::Draw(const std::shared_ptr<flutter::Pipeline<flutter::FrameItem>> & pipeline) Line 256	C++
 	[Inline Frame] flutter_windows.dll!flutter::Shell::OnAnimatorDraw::<lambda_38>::operator()() Line 1274	C++
 	[Inline Frame] flutter_windows.dll!fml::internal::CopyableLambda<`lambda at ..\..\flutter\shell\common\shell.cc:1267:7'>::operator()() Line 24	C++
 	[Inline Frame] flutter_windows.dll!std::invoke(fml::internal::CopyableLambda<`lambda at ..\..\flutter\shell\common\shell.cc:1267:7'> & _Obj) Line 1562	C++
 	[Inline Frame] flutter_windows.dll!std::_Invoker_ret<void>::_Call(fml::internal::CopyableLambda<`lambda at ..\..\flutter\shell\common\shell.cc:1267:7'> & _Func) Line 670	C++
 	flutter_windows.dll!std::_Func_impl_no_alloc<fml::internal::CopyableLambda<`lambda at ..\..\flutter\shell\common\shell.cc:1267:7'>,void>::_Do_call() Line 833	C++
 	[Inline Frame] flutter_windows.dll!std::_Func_class<void>::operator()() Line 874	C++
 	flutter_windows.dll!fml::MessageLoopImpl::FlushTasks(fml::FlushType type) Line 127	C++
 	flutter_windows.dll!fml::MessageLoopWin::Run() Line 39	C++
 	flutter_windows.dll!fml::MessageLoopImpl::DoRun() Line 94	C++
 	[Inline Frame] flutter_windows.dll!fml::Thread::Thread::<lambda_2>::operator()() Line 154	C++
 	[Inline Frame] flutter_windows.dll!std::invoke(fml::Thread::Thread::<lambda_2> & _Obj) Line 1562	C++
 	[Inline Frame] flutter_windows.dll!std::_Invoker_ret<void>::_Call(fml::Thread::Thread::<lambda_2> & _Func) Line 670	C++
 	flutter_windows.dll!std::_Func_impl_no_alloc<`lambda at ..\..\flutter\fml\thread.cc:148:7',void>::_Do_call() Line 833	C++
 	[Inline Frame] flutter_windows.dll!std::_Func_class<void>::operator()() Line 874	C++
 	[Inline Frame] flutter_windows.dll!fml::ThreadHandle::ThreadHandle::<lambda_1>::operator()(void * arg) Line 51	C++
 	flutter_windows.dll!fml::ThreadHandle::ThreadHandle::<lambda_1>::__invoke(void * arg) Line 48	C++
>	flutter_windows.dll!thread_start<unsigned int (__cdecl*)(void *),1>(void * const parameter) Line 97	C++
 	kernel32.dll!00007ffd21847374()	Unknown
 	ntdll.dll!00007ffd21ddcc91()	Unknown

Crash call stack img:

call-stack

Parallel stack:

parallel-stack

Exception:

exception

Additionally, it seems it isn't the only place where the app crashes when using the plugin. Some extra logs from my app:

24_07_2024_11_58_46 -1721815126 threads2 24_07_2024_12_33_10 -1721817190 23_07_2024_14_17_06 -1721737026

lukasz-lukasz-lukasz avatar Jul 25 '24 11:07 lukasz-lukasz-lukasz

I reported it directly in the Flutter repository but was sent here: https://github.com/flutter/flutter/issues/152299

lukasz-lukasz-lukasz avatar Jul 25 '24 12:07 lukasz-lukasz-lukasz

Hi @fufesou πŸ‘‹

I saw that you made a great contribution πŸ’ͺ to resolve the issue I reported some time ago: https://github.com/MixinNetwork/flutter-plugins/issues/283

It seems this issue is similar.. but we are crashing in different places inside the Flutter engine.. some details here: https://github.com/flutter/flutter/issues/152299

I committed a piece of code here that automates the crash reproduction: https://github.com/lukasz-lukasz-lukasz/flutter-plugins/commit/4ae8e28318187ee8936ffcccdd37c3d433e53f15

03_09_2024_17_52_05 -1725378725
  • all we need is to click one button and wait until the app crashes.. :)

Since you have experience with the previous issue, maybe you would like to help with this one if you have time.. πŸ™ πŸ™ πŸ˜„

lukasz-lukasz-lukasz avatar Sep 03 '24 15:09 lukasz-lukasz-lukasz

I recently encountered this too, creating and opening randomness would crash the entire program,I hope the author can pay attention to it, thank you

lingg4556 avatar Sep 23 '24 09:09 lingg4556

@lukasz-lukasz-lukasz I have the same problem, did you solve it?

weedsboy avatar Nov 18 '24 01:11 weedsboy

@lukasz-lukasz-lukasz I think this should be a problem with flutter. It was normal before flutter was upgraded. When I upgraded to flutter 3.24, it crashed.

weedsboy avatar Nov 18 '24 01:11 weedsboy

I have same problem, any suggestion?

NicholasHwang avatar Dec 30 '24 07:12 NicholasHwang

@lukasz-lukasz-lukasz @lingg4556 @NicholasHwang I fixed this issue, and it works well. I hope this can help you.

https://github.com/weedsboy/engine/tree/3.22.3_fix_issues for flutter 3.22.3 https://github.com/weedsboy/engine/tree/3.24.4_fix_issues for flutter 3.24.4

weedsboy avatar Dec 30 '24 07:12 weedsboy

More related solutions:

Per this thread https://github.com/flutter/flutter/issues/155685, this MR is root cause of crashing

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 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

OR

  • using experimental patch 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

isaacy13 avatar Jan 11 '25 04:01 isaacy13

@weedsboy hallo, My problem is flutter 3.19.6, so I can modify like as your fix in 3.22.3?

NicholasHwang avatar Jan 13 '25 05:01 NicholasHwang

@weedsboy hallo, My problem is flutter 3.19.6, so I can modify like as your fix in 3.22.3?

There have been big changes in Flutter from version 3.19 to 3.22. This might not work, but you can give it a try.

weedsboy avatar Jan 13 '25 07:01 weedsboy

More related solutions:

Per this thread flutter/flutter#155685, this MR is root cause of crashing

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 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

OR

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

I have same crash on flutter 3.19.6, did you resolved on flutter 3.16.8?

NicholasHwang avatar Jan 17 '25 02:01 NicholasHwang

Hey @NicholasHwang, yes, downgrading to flutter v3.16.8 fixed all crashing for me

isaacy13 avatar Jan 17 '25 02:01 isaacy13

@weedsboy hallo, I use 3.24.5 and modify as your MR. after build engine, I run desktop_multi_window example, it leak memory. do we have any solution to fix memory leak?

NicholasHwang avatar Jan 21 '25 09:01 NicholasHwang

@weedsboy hallo, I use 3.24.5 and modify as your MR. after build engine, I run desktop_multi_window example, it leak memory. do we have any solution to fix memory leak?

I haven't encountered any memory leaks yet. Can you see where the leak is?

weedsboy avatar Jan 24 '25 01:01 weedsboy

Image @weedsboy modified demo mr: https://github.com/lukasz-lukasz-lukasz/flutter-plugins/commit/4ae8e28318187ee8936ffcccdd37c3d433e53f15

NicholasHwang avatar Jan 26 '25 07:01 NicholasHwang

@lukasz-lukasz-lukasz @lingg4556 @NicholasHwang I fixed this issue, and it works well. I hope this can help you.

https://github.com/weedsboy/engine/tree/3.22.3_fix_issues for flutter 3.22.3 https://github.com/weedsboy/engine/tree/3.24.4_fix_issues for flutter 3.24.4

Can you provide a fixed version of the dynamic library? flutter_windows.dll based on 3.24.4. Thanks

zhangc20 avatar Mar 20 '25 03:03 zhangc20

@lukasz-lukasz-lukasz @lingg4556 @NicholasHwang I fixed this issue, and it works well. I hope this can help you. https://github.com/weedsboy/engine/tree/3.22.3_fix_issues for flutter 3.22.3 https://github.com/weedsboy/engine/tree/3.24.4_fix_issues for flutter 3.24.4

Can you provide a fixed version of the dynamic library? flutter_windows.dll based on 3.24.4. Thanks

give me a email.

weedsboy avatar Mar 20 '25 04:03 weedsboy

@lukasz-lukasz-lukasz @lingg4556 @NicholasHwang I fixed this issue, and it works well. I hope this can help you. https://github.com/weedsboy/engine/tree/3.22.3_fix_issues for flutter 3.22.3 https://github.com/weedsboy/engine/tree/3.24.4_fix_issues for flutter 3.24.4

Can you provide a fixed version of the dynamic library? flutter_windows.dll based on 3.24.4. Thanks

give me a email.

Thank you, email: [email protected]

zhangc20 avatar Mar 20 '25 06:03 zhangc20

@lukasz-lukasz-lukasz @lingg4556 @NicholasHwang I fixed this issue, and it works well. I hope this can help you.

https://github.com/weedsboy/engine/tree/3.22.3_fix_issues for flutter 3.22.3 https://github.com/weedsboy/engine/tree/3.24.4_fix_issues for flutter 3.24.4

For some reason, this doesn't work for me on 3.24.4. Is it just me?

Edit: Oh, it looks like I need to compile the engine. If you'd also send the dll, I'd appreciate it very much. My email is [mailto:[email protected]]

ItsVeridian avatar Apr 02 '25 12:04 ItsVeridian

it's also not working on Flutter 3.35.2 β€’ channel stable. Any workaround or solutions for now?

tologonkudaiberdiuulu avatar Sep 11 '25 13:09 tologonkudaiberdiuulu