From 353b33b7c33e5b4a0a2c2f954869b449f45dc2fc Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Mon, 7 Jul 2025 17:37:28 +0800 Subject: [PATCH] fix: addDestroySwapchain argument to createViewer() (true by default). This is only used on iOS/macOS where a single swapchain is shared between all render targets --- .../lib/src/thermion_flutter_plugin.dart | 4 ++-- ...thermion_flutter_method_channel_platform.dart | 16 ++++++++++------ .../lib/thermion_flutter_platform_interface.dart | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/thermion_flutter/thermion_flutter/lib/src/thermion_flutter_plugin.dart b/thermion_flutter/thermion_flutter/lib/src/thermion_flutter_plugin.dart index 94dcb077..7d40b4c7 100644 --- a/thermion_flutter/thermion_flutter/lib/src/thermion_flutter_plugin.dart +++ b/thermion_flutter/thermion_flutter/lib/src/thermion_flutter_plugin.dart @@ -11,8 +11,8 @@ import 'package:thermion_flutter_platform_interface/thermion_flutter_platform_in class ThermionFlutterPlugin { ThermionFlutterPlugin._(); - static Future createViewer() { - return ThermionFlutterPlatform.instance.createViewer(); + static Future createViewer({bool destroySwapchain = true}) { + return ThermionFlutterPlatform.instance.createViewer(destroySwapchain: destroySwapchain); } } diff --git a/thermion_flutter/thermion_flutter_method_channel/lib/src/thermion_flutter_method_channel_platform.dart b/thermion_flutter/thermion_flutter_method_channel/lib/src/thermion_flutter_method_channel_platform.dart index bc058eca..6412f69d 100644 --- a/thermion_flutter/thermion_flutter_method_channel/lib/src/thermion_flutter_method_channel_platform.dart +++ b/thermion_flutter/thermion_flutter_method_channel/lib/src/thermion_flutter_method_channel_platform.dart @@ -46,7 +46,7 @@ class ThermionFlutterMethodChannelPlatform extends ThermionFlutterPlatform { return asset.buffer.asUint8List(asset.offsetInBytes); } - Future createViewer() async { + Future createViewer({bool destroySwapchain = true}) async { var driverPlatform = await channel.invokeMethod("getDriverPlatform"); var platformPtr = driverPlatform == null @@ -118,7 +118,13 @@ class ThermionFlutterMethodChannelPlatform extends ThermionFlutterPlatform { // TODO - see if we can use `renderStandaloneView` in FilamentViewer to // avoid this if (Platform.isMacOS || Platform.isIOS) { - _swapChain = await FilamentApp.instance!.createHeadlessSwapChain(1, 1, hasStencilBuffer: true); + if(destroySwapchain && _swapChain != null) { + await FilamentApp.instance!.destroySwapChain(_swapChain!); + _swapChain = null; + } + + _swapChain ??= await FilamentApp.instance! + .createHeadlessSwapChain(1, 1, hasStencilBuffer: true); await FilamentApp.instance!.register(_swapChain!, viewer.view); await viewer.view.setRenderable(true); } @@ -179,10 +185,8 @@ class ThermionFlutterMethodChannelPlatform extends ThermionFlutterPlatform { } _swapChain = await FilamentApp.instance!.createHeadlessSwapChain( - descriptor.width, - descriptor.height, - hasStencilBuffer: true - ); + descriptor.width, descriptor.height, + hasStencilBuffer: true); _logger.info( "Created headless swapchain ${descriptor.width}x${descriptor.height}", diff --git a/thermion_flutter/thermion_flutter_platform_interface/lib/thermion_flutter_platform_interface.dart b/thermion_flutter/thermion_flutter_platform_interface/lib/thermion_flutter_platform_interface.dart index c1661467..6a233683 100644 --- a/thermion_flutter/thermion_flutter_platform_interface/lib/thermion_flutter_platform_interface.dart +++ b/thermion_flutter/thermion_flutter_platform_interface/lib/thermion_flutter_platform_interface.dart @@ -65,7 +65,7 @@ abstract class ThermionFlutterPlatform extends PlatformInterface { /// /// /// - Future createViewer() { + Future createViewer({bool destroySwapchain = true}) { throw UnimplementedError(); }