From aa2f19442bbbf462e039a9d027331c79909d8c5b Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Wed, 4 Jun 2025 11:13:15 +0800 Subject: [PATCH] surround frame request hooks with try/catch, and add a check to avoid concurrency exceptions when adding/removing hooks --- .../src/implementation/ffi_filament_app.dart | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/thermion_dart/lib/src/filament/src/implementation/ffi_filament_app.dart b/thermion_dart/lib/src/filament/src/implementation/ffi_filament_app.dart index c71dacbc..4f004652 100644 --- a/thermion_dart/lib/src/filament/src/implementation/ffi_filament_app.dart +++ b/thermion_dart/lib/src/filament/src/implementation/ffi_filament_app.dart @@ -619,6 +619,9 @@ class FFIFilamentApp extends FilamentApp { /// @override Future registerRequestFrameHook(Future Function() hook) async { + while (_requesting) { + await Future.delayed(Duration(milliseconds: 1)); + } if (!_hooks.contains(hook)) { _hooks.add(hook); } @@ -629,20 +632,30 @@ class FFIFilamentApp extends FilamentApp { /// @override Future unregisterRequestFrameHook(Future Function() hook) async { + while (_requesting) { + await Future.delayed(Duration(milliseconds: 1)); + } if (_hooks.contains(hook)) { _hooks.remove(hook); } } + bool _requesting = false; + /// /// /// @override Future requestFrame() async { - for (final hook in _hooks) { - await hook.call(); + _requesting = true; + try { + for (final hook in _hooks) { + await hook.call(); + } + } catch (err) { + _logger.severe(err); } - + _requesting = false; RenderThread_requestFrameAsync(); }