Repository: flutter
Issue: glfw example crashes when resizing the window
Labels: engine,d: examples,P2,team-engine,triaged-engine

There is a crash when resizing the glfw example.

## error text

-[AGXG13XFamilyCommandBuffer renderCommandEncoderWithDescriptor:]:380: failed assertion `A command encoder is already encoding to this command buffer'
./run.sh: line 37: 24752 Abort trap: 6           ./flutter_glfw ./myapp ../../../../third_party/icu/common/icudtl.dat

## steps to reproduce
1) cd //examples/glfw
1) ./run.sh
1) start resizing the window

## engine version
985f4ac51eb8edc8e009fb6582cfd03db47a9e1e

## doctor

```
[!] Flutter (Channel unknown, 3.7.0-10.0.pre.24, on macOS 12.6.2 21G320 darwin-arm64, locale en)
    ! Flutter version 3.7.0-10.0.pre.24 on channel unknown at /Users/aaclarke/dev/flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
    ! Unknown upstream repository.
      Reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
    • Framework revision 66dcf5dd43 (4 days ago), 2022-12-16 14:14:09 -0800
    • Engine revision 29196519c1
    • Dart version 3.0.0 (build 3.0.0-21.0.dev)
    • DevTools version 2.20.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
```

## crash
[crashlog.txt](https://github.com/flutter/flutter/files/10272096/crashlog.txt)

## stacktrace
```
Thread 5 Crashed:: io.flutter.raster
0   libsystem_kernel.dylib        	       0x1bce9ed98 __pthread_kill + 8
1   libsystem_pthread.dylib       	       0x1bced3ee0 pthread_kill + 288
2   libsystem_c.dylib             	       0x1bce0e340 abort + 168
3   libsystem_c.dylib             	       0x1bce0d754 __assert_rtn + 272
4   Metal                         	       0x1c58cedd8 MTLReportFailure.cold.1 + 56
5   Metal                         	       0x1c58b8790 MTLReportFailure + 480
6   AGXMetalG13X                  	       0x203ae526c 0x2038f4000 + 2036332
7   AppleMetalOpenGLRenderer      	       0x1087e0184 GLDContextRec::beginRenderPass() + 136
8   AppleMetalOpenGLRenderer      	       0x1087f7884 gldRenderVertexArray(GLDContextRec*, unsigned int, unsigned int, int, int, unsigned int, void const*, int, void const*) + 500
9   GLEngine                      	       0x21e922ac8 glDrawRangeElements_ACC_Exec + 452
10  FlutterEmbedder               	       0x110e9c9c8 GrGLFunction<void (unsigned int, unsigned int, unsigned int, int, unsigned int, void const*)>::GrGLFunction(void (*)(unsigned int, unsigned int, unsigned int, int, unsigned int, void const*))::'lambda'(void const*, unsigned int, unsigned int, unsigned int, int, unsigned int, void const*)::operator()(void const*, unsigned int, unsigned int, unsigned int, int, unsigned int, void const*) const + 96
11  FlutterEmbedder               	       0x110e9c938 GrGLFunction<void (unsigned int, unsigned int, unsigned int, int, unsigned int, void const*)>::GrGLFunction(void (*)(unsigned int, unsigned int, unsigned int, int, unsigned int, void const*))::'lambda'(void const*, unsigned int, unsigned int, unsigned int, int, unsigned int, void const*)::__invoke(void const*, unsigned int, unsigned int, unsigned int, int, unsigned int, void const*) + 92
12  FlutterEmbedder               	       0x110f1209c GrGLFunction<void (unsigned int, unsigned int, unsigned int, int, unsigned int, void const*)>::operator()(unsigned int, unsigned int, unsigned int, int, unsigned int, void const*) const + 140
13  FlutterEmbedder               	       0x110f11c44 GrGLOpsRenderPass::onDrawIndexed(int, int, unsigned short, unsigned short, int) + 588
14  FlutterEmbedder               	       0x110b7ed94 GrOpsRenderPass::drawIndexed(int, int, unsigned short, unsigned short, int) + 232
15  FlutterEmbedder               	       0x110b74604 GrOpFlushState::drawIndexed(int, int, unsigned short, unsigned short, int) + 84
16  FlutterEmbedder               	       0x110b721d8 GrOpFlushState::drawMesh(GrSimpleMesh const&) + 340
17  FlutterEmbedder               	       0x110e0104c (anonymous namespace)::ShadowCircularRRectOp::onExecute(GrOpFlushState*, SkRect const&) + 292
18  FlutterEmbedder               	       0x110dc9aa4 GrOp::execute(GrOpFlushState*, SkRect const&) + 316
19  FlutterEmbedder               	       0x110dc9370 skgpu::v1::OpsTask::onExecute(GrOpFlushState*) + 1592
20  FlutterEmbedder               	       0x110ad305c GrRenderTask::execute(GrOpFlushState*) + 56
21  FlutterEmbedder               	       0x110b107ec GrDrawingManager::executeRenderTasks(GrOpFlushState*) + 384
22  FlutterEmbedder               	       0x110b0f070 GrDrawingManager::flush(SkSpan<GrSurfaceProxy*>, SkSurface::BackendSurfaceAccess, GrFlushInfo const&, skgpu::MutableTextureState const*) + 1720
23  FlutterEmbedder               	       0x110b1293c GrDrawingManager::flushSurfaces(SkSpan<GrSurfaceProxy*>, SkSurface::BackendSurfaceAccess, GrFlushInfo const&, skgpu::MutableTextureState const*) + 372
24  FlutterEmbedder               	       0x110ae277c GrDirectContext::flush(GrFlushInfo const&) + 276
25  FlutterEmbedder               	       0x10f8b7b6c GrDirectContext::flushAndSubmit(bool) + 92
26  FlutterEmbedder               	       0x11025dabc SkCanvas::onFlush() + 92
27  FlutterEmbedder               	       0x11025da30 SkCanvas::flush() + 48
28  FlutterEmbedder               	       0x1126a1c88 flutter::GPUSurfaceGLSkia::PresentSurface(flutter::SurfaceFrame const&, SkCanvas*) + 244
29  FlutterEmbedder               	       0x1126a927c flutter::GPUSurfaceGLSkia::AcquireFrame(SkISize const&)::$_1::operator()(flutter::SurfaceFrame const&, SkCanvas*) const + 80
30  FlutterEmbedder               	       0x1126a91f0 decltype(std::declval<flutter::GPUSurfaceGLSkia::AcquireFrame(SkISize const&)::$_1&>()(std::declval<flutter::SurfaceFrame&>(), std::declval<SkCanvas*>())) std::_LIBCPP_ABI_NAMESPACE::__invoke[abi:v15000]<flutter::GPUSurfaceGLSkia::AcquireFrame(SkISize const&)::$_1&, flutter::SurfaceFrame&, SkCanvas*>(flutter::GPUSurfaceGLSkia::AcquireFrame(SkISize const&)::$_1&, flutter::SurfaceFrame&, SkCanvas*&&) + 60
31  FlutterEmbedder               	       0x1126a9118 bool std::_LIBCPP_ABI_NAMESPACE::__invoke_void_return_wrapper<bool, false>::__call<flutter::GPUSurfaceGLSkia::AcquireFrame(SkISize const&)::$_1&, flutter::SurfaceFrame&, SkCanvas*>(flutter::GPUSurfaceGLSkia::AcquireFrame(SkISize const&)::$_1&, flutter::SurfaceFrame&, SkCanvas*&&) + 56
32  FlutterEmbedder               	       0x1126a90a4 std::_LIBCPP_ABI_NAMESPACE::__function::__alloc_func<flutter::GPUSurfaceGLSkia::AcquireFrame(SkISize const&)::$_1, std::_LIBCPP_ABI_NAMESPACE::allocator<flutter::GPUSurfaceGLSkia::AcquireFrame(SkISize const&)::$_1>, bool (flutter::SurfaceFrame&, SkCanvas*)>::operator()[abi:v15000](flutter::SurfaceFrame&, SkCanvas*&&) + 60
33  FlutterEmbedder               	       0x1126a6ae8 std::_LIBCPP_ABI_NAMESPACE::__function::__func<flutter::GPUSurfaceGLSkia::AcquireFrame(SkISize const&)::$_1, std::_LIBCPP_ABI_NAMESPACE::allocator<flutter::GPUSurfaceGLSkia::AcquireFrame(SkISize const&)::$_1>, bool (flutter::SurfaceFrame&, SkCanvas*)>::operator()(flutter::SurfaceFrame&, SkCanvas*&&) + 60
34  FlutterEmbedder               	       0x111538d58 std::_LIBCPP_ABI_NAMESPACE::__function::__value_func<bool (flutter::SurfaceFrame&, SkCanvas*)>::operator()[abi:v15000](flutter::SurfaceFrame&, SkCanvas*&&) const + 100
35  FlutterEmbedder               	       0x111537b74 std::_LIBCPP_ABI_NAMESPACE::function<bool (flutter::SurfaceFrame&, SkCanvas*)>::operator()(flutter::SurfaceFrame&, SkCanvas*) const + 60
36  FlutterEmbedder               	       0x11153792c flutter::SurfaceFrame::PerformSubmit() + 116
37  FlutterEmbedder               	       0x111537844 flutter::SurfaceFrame::Submit() + 128
38  FlutterEmbedder               	       0x111588688 flutter::Rasterizer::DrawToSurfaceUnsafe(flutter::FrameTimingsRecorder&, flutter::LayerTree&) + 2292
39  FlutterEmbedder               	       0x111585918 flutter::Rasterizer::DrawToSurface(flutter::FrameTimingsRecorder&, flutter::LayerTree&) + 276
40  FlutterEmbedder               	       0x111587108 flutter::Rasterizer::DoDraw(std::_LIBCPP_ABI_NAMESPACE::unique_ptr<flutter::FrameTimingsRecorder, std::_LIBCPP_ABI_NAMESPACE::default_delete<flutter::FrameTimingsRecorder> >, std::_LIBCPP_ABI_NAMESPACE::shared_ptr<flutter::LayerTree>) + 428
```

cc @chinmaygarde (this is potentially a p1)