properly null out texture references on disposal

This commit is contained in:
Nick Fisher
2025-04-02 22:27:36 +08:00
parent e0b2e1c3b9
commit 7d8f7a726b

View File

@@ -56,10 +56,12 @@ class _ThermionTextureWidgetState extends State<ThermionTextureWidget> {
@override @override
void dispose() { void dispose() {
final texture = _texture;
_texture = null;
super.dispose(); super.dispose();
_views.remove(widget.viewer.view); _views.remove(widget.viewer.view);
if (_texture != null) { if (texture != null) {
ThermionFlutterPlatform.instance.destroyTextureDescriptor(_texture!); ThermionFlutterPlatform.instance.destroyTextureDescriptor(texture!);
} }
_fpsUpdateTimer?.cancel(); _fpsUpdateTimer?.cancel();
_states.remove(this); _states.remove(this);
@@ -131,6 +133,7 @@ class _ThermionTextureWidgetState extends State<ThermionTextureWidget> {
widget.viewer.onDispose(() async { widget.viewer.onDispose(() async {
var texture = _texture; var texture = _texture;
_texture = null;
if (mounted) { if (mounted) {
setState(() {}); setState(() {});
} }