From 7d8f7a726b39353445c61e36402cba1919c5b03e Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Wed, 2 Apr 2025 22:27:36 +0800 Subject: [PATCH] properly null out texture references on disposal --- .../lib/src/widgets/src/thermion_texture_widget.dart | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/thermion_flutter/thermion_flutter/lib/src/widgets/src/thermion_texture_widget.dart b/thermion_flutter/thermion_flutter/lib/src/widgets/src/thermion_texture_widget.dart index f334b997..83f4cf21 100644 --- a/thermion_flutter/thermion_flutter/lib/src/widgets/src/thermion_texture_widget.dart +++ b/thermion_flutter/thermion_flutter/lib/src/widgets/src/thermion_texture_widget.dart @@ -56,10 +56,12 @@ class _ThermionTextureWidgetState extends State { @override void dispose() { + final texture = _texture; + _texture = null; super.dispose(); _views.remove(widget.viewer.view); - if (_texture != null) { - ThermionFlutterPlatform.instance.destroyTextureDescriptor(_texture!); + if (texture != null) { + ThermionFlutterPlatform.instance.destroyTextureDescriptor(texture!); } _fpsUpdateTimer?.cancel(); _states.remove(this); @@ -131,6 +133,7 @@ class _ThermionTextureWidgetState extends State { widget.viewer.onDispose(() async { var texture = _texture; + _texture = null; if (mounted) { setState(() {}); }