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 e3093398..536a7d52 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 @@ -44,16 +44,10 @@ class ThermionFlutterMethodChannelPlatform extends ThermionFlutterPlatform { } Future createViewer({ThermionFlutterOptions? options}) async { - var resourceLoader = Pointer.fromAddress( - await channel.invokeMethod("getResourceLoaderWrapper")); - - if (resourceLoader == nullptr) { - throw Exception("Failed to get resource loader"); - } var driverPlatform = await channel.invokeMethod("getDriverPlatform"); - var driverPtr = driverPlatform == null + var platformPtr = driverPlatform == null ? nullptr : Pointer.fromAddress(driverPlatform); @@ -97,12 +91,17 @@ class ThermionFlutterMethodChannelPlatform extends ThermionFlutterPlatform { final config = FFIFilamentConfig( backend: backend, resourceLoader: loadAsset, - driver: driverPtr, - platform: nullptr, + platform: platformPtr, sharedContext: sharedContextPtr, uberArchivePath: options?.uberarchivePath); - await FFIFilamentApp.create(config: config); + if (FilamentApp.instance == null) { + await FFIFilamentApp.create(config: config); + FilamentApp.instance!.onDestroy(() async { + await channel.invokeMethod("destroyContext"); + _swapChain = null; + }); + } final viewer = ThermionViewerFFI( loadAssetFromUri: loadAsset, @@ -110,8 +109,6 @@ class ThermionFlutterMethodChannelPlatform extends ThermionFlutterPlatform { await viewer.initialized; - viewer.onDispose(() async {}); - // this implementation renders directly into a texture/render target // for some reason we still need to create a (headless) swapchain, but the // actual dimensions don't matter @@ -213,6 +210,7 @@ class ThermionFlutterMethodChannelPlatform extends ThermionFlutterPlatform { View view, int width, int height) async { + var newTexture = await createTextureAndBindToView(view, width, height); if (newTexture == null) { throw Exception();