MixinNetwork / flutter-plugins

🧱 Flutter plugins used in Mixin Messenger.
MIT License
436 stars 183 forks source link

[desktop_multi_window] App is crashing while closing windows #352

Open lukasz-lukasz-lukasz opened 1 month ago

lukasz-lukasz-lukasz commented 1 month ago

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

• 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 commented 1 month ago

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

lukasz-lukasz-lukasz commented 4 days ago

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

Since you have experience with the previous issue, maybe you would like to help with this one if you have time.. 🙏 🙏 😄