From 013730b10851b341d44edc64df0ac6f2c60cb96b Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Wed, 19 Jun 2024 16:39:10 +0800 Subject: [PATCH] destroy existing texture if it exists but size does match requested dimensions when createTexture is called --- .../lib/thermion_flutter_ffi.dart | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/thermion_flutter/thermion_flutter_ffi/lib/thermion_flutter_ffi.dart b/thermion_flutter/thermion_flutter_ffi/lib/thermion_flutter_ffi.dart index 77cdcea8..9a930778 100644 --- a/thermion_flutter/thermion_flutter_ffi/lib/thermion_flutter_ffi.dart +++ b/thermion_flutter/thermion_flutter_ffi/lib/thermion_flutter_ffi.dart @@ -109,10 +109,15 @@ class ThermionFlutterFFI extends ThermionFlutterPlatform { if (_textures.length > 1) { throw Exception("Multiple textures not yet supported"); - } else if (_textures.length == 1 && - _textures.first.height == height && - _textures.first.width == width) { - return _textures.first; + } else if (_textures.length == 1) { + if (_textures.first.height == height && _textures.first.width == width) { + return _textures.first; + } else { + await _viewer!.setRendering(false); + await _viewer!.destroySwapChain(); + await destroyTexture(_textures.first); + _textures.clear(); + } } _creatingTexture = true; @@ -146,7 +151,8 @@ class ThermionFlutterFFI extends ThermionFlutterPlatform { width.toDouble(), height.toDouble(), texture.hardwareTextureId!); } - await _viewer?.updateViewportAndCameraProjection(width.toDouble(), height.toDouble()); + await _viewer?.updateViewportAndCameraProjection( + width.toDouble(), height.toDouble()); _viewer?.render(); _creatingTexture = false; @@ -155,13 +161,13 @@ class ThermionFlutterFFI extends ThermionFlutterPlatform { return texture; } - /// /// Destroy a texture and clean up the texture cache (if applicable). /// Future destroyTexture(ThermionFlutterTexture texture) async { if (_creatingTexture || _destroyingTexture) { - throw Exception("Cannot destroy texture while concurrent call to createTexture/destroyTexture has not completed"); + throw Exception( + "Cannot destroy texture while concurrent call to createTexture/destroyTexture has not completed"); } _destroyingTexture = true; _textures.remove(texture);