From 837a2cebc7b677e71cd89a19f47ddea03a7e6e61 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Tue, 17 Oct 2023 00:25:30 +1100 Subject: [PATCH] different timeouts for resize in debug/release --- lib/widgets/filament_widget.dart | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/widgets/filament_widget.dart b/lib/widgets/filament_widget.dart index 39b57080..c03fdbac 100644 --- a/lib/widgets/filament_widget.dart +++ b/lib/widgets/filament_widget.dart @@ -161,9 +161,17 @@ class _SizedFilamentWidgetState extends State<_SizedFilamentWidget> { Future _resize() { final completer = Completer(); + // resizing the window can be sluggish (particular in debug mode), exacerbated when simultaneously recreating the swapchain and resize the window. + // to address this, whenever the widget is resized, we set a timer for Xms in the future. + // this timer will call [resize] with the widget size at that point in time. + // any subsequent widget resizes will cancel the timer and replace with a new one. + // debug mode does need a longer timeout. _resizeTimer?.cancel(); - _resizeTimer = Timer(Duration(milliseconds: 200), () async { + _resizeTimer = Timer(const Duration(milliseconds: kReleaseMode ? 20 : 100), () async { + if(!mounted) { + return; + } var size = ((context.findRenderObject()) as RenderBox).size; var width = size.width.ceil(); var height = size.height.ceil();