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

This commit is contained in:
Nick Fisher
2025-07-07 17:37:28 +08:00
parent 3c1b26af2c
commit 353b33b7c3
3 changed files with 13 additions and 9 deletions

View File

@@ -11,8 +11,8 @@ import 'package:thermion_flutter_platform_interface/thermion_flutter_platform_in
class ThermionFlutterPlugin {
ThermionFlutterPlugin._();
static Future<ThermionViewer> createViewer() {
return ThermionFlutterPlatform.instance.createViewer();
static Future<ThermionViewer> createViewer({bool destroySwapchain = true}) {
return ThermionFlutterPlatform.instance.createViewer(destroySwapchain: destroySwapchain);
}
}

View File

@@ -46,7 +46,7 @@ class ThermionFlutterMethodChannelPlatform extends ThermionFlutterPlatform {
return asset.buffer.asUint8List(asset.offsetInBytes);
}
Future<ThermionViewer> createViewer() async {
Future<ThermionViewer> 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}",

View File

@@ -65,7 +65,7 @@ abstract class ThermionFlutterPlatform extends PlatformInterface {
///
///
///
Future<ThermionViewer> createViewer() {
Future<ThermionViewer> createViewer({bool destroySwapchain = true}) {
throw UnimplementedError();
}