[web] Fix HtmlViewEmbedder.dispose (flutter/engine#50482)
Fix a `Concurrent modification during iteration` in the `dispose` method of the HtmlViewEmbedder. ### Issues Fixes https://github.com/flutter/flutter/issues/143193 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
@@ -658,7 +658,7 @@ class HtmlViewEmbedder {
|
||||
|
||||
/// Disposes the state of this view embedder.
|
||||
void dispose() {
|
||||
disposeViews(_viewClipChains.keys);
|
||||
disposeViews(_viewClipChains.keys.toList());
|
||||
_context = EmbedderFrameContext();
|
||||
_currentCompositionParams.clear();
|
||||
debugCleanupSvgClipPaths();
|
||||
|
||||
@@ -974,6 +974,43 @@ void testMain() {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('can dispose without crashing', () async {
|
||||
ui_web.platformViewRegistry.registerViewFactory(
|
||||
'test-view',
|
||||
(int viewId) =>
|
||||
createDomHTMLDivElement()..className = 'platform-view',
|
||||
isVisible: false);
|
||||
|
||||
await createPlatformView(0, 'test-view');
|
||||
await createPlatformView(1, 'test-view');
|
||||
await createPlatformView(2, 'test-view');
|
||||
|
||||
final LayerSceneBuilder sb = LayerSceneBuilder()
|
||||
..pushOffset(0, 0)
|
||||
..addPlatformView(0, width: 10, height: 10)
|
||||
..addPlatformView(1, width: 10, height: 10)
|
||||
..addPlatformView(2, width: 10, height: 10)
|
||||
..pop();
|
||||
|
||||
await renderScene(sb.build());
|
||||
|
||||
_expectSceneMatches(<_EmbeddedViewMarker>[
|
||||
_overlay,
|
||||
_platformView,
|
||||
_platformView,
|
||||
_platformView,
|
||||
]);
|
||||
|
||||
expect(() {
|
||||
final HtmlViewEmbedder embedder =
|
||||
(renderer as CanvasKitRenderer)
|
||||
.debugGetRasterizerForView(implicitView)!
|
||||
.viewEmbedder;
|
||||
// The following line used to cause a "Concurrent modification during iteration"
|
||||
embedder.dispose();
|
||||
}, returnsNormally);
|
||||
});
|
||||
}
|
||||
|
||||
// Used to test that the platform views and overlays are in the correct order in
|
||||
|
||||
Reference in New Issue
Block a user