fix: add listener in ThermionFlutterTextureBackedPlatform to unset viewer on dispose
This commit is contained in:
@@ -14,12 +14,11 @@ import 'platform_texture.dart';
|
|||||||
///
|
///
|
||||||
/// An implementation of [ThermionFlutterPlatform] that uses
|
/// An implementation of [ThermionFlutterPlatform] that uses
|
||||||
/// Flutter platform channels to create a rendering context,
|
/// Flutter platform channels to create a rendering context,
|
||||||
/// resource loaders, and a texture that will be used as a render target
|
/// resource loaders, and a texture that will be used as a render target
|
||||||
/// for a headless swapchain.
|
/// for a headless swapchain.
|
||||||
///
|
///
|
||||||
class ThermionFlutterTextureBackedPlatform
|
class ThermionFlutterTextureBackedPlatform
|
||||||
extends ThermionFlutterMethodChannelInterface {
|
extends ThermionFlutterMethodChannelInterface {
|
||||||
|
|
||||||
final _logger = Logger("ThermionFlutterTextureBackedPlatform");
|
final _logger = Logger("ThermionFlutterTextureBackedPlatform");
|
||||||
|
|
||||||
static SwapChain? _swapChain;
|
static SwapChain? _swapChain;
|
||||||
@@ -46,20 +45,27 @@ class ThermionFlutterTextureBackedPlatform
|
|||||||
if (Platform.isMacOS || Platform.isIOS) {
|
if (Platform.isMacOS || Platform.isIOS) {
|
||||||
_swapChain = await viewer.createHeadlessSwapChain(1, 1);
|
_swapChain = await viewer.createHeadlessSwapChain(1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewer.onDispose(() async {
|
||||||
|
_swapChain = null;
|
||||||
|
});
|
||||||
|
|
||||||
return viewer;
|
return viewer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// On desktop platforms, textures are always created
|
// On desktop platforms, textures are always created
|
||||||
Future<ThermionFlutterTexture?> createTexture(t.View view, int width, int height) async {
|
Future<ThermionFlutterTexture?> createTexture(
|
||||||
var texture = FlutterPlatformTexture(channel, viewer!, view, (Platform.isMacOS || Platform.isIOS)? _swapChain : null);
|
t.View view, int width, int height) async {
|
||||||
|
var texture = FlutterPlatformTexture(channel, viewer!, view,
|
||||||
|
(Platform.isMacOS || Platform.isIOS) ? _swapChain : null);
|
||||||
await texture.resize(width, height, 0, 0);
|
await texture.resize(width, height, 0, 0);
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<ThermionFlutterWindow> createWindow(int width, int height, int offsetLeft, int offsetTop) {
|
Future<ThermionFlutterWindow> createWindow(
|
||||||
|
int width, int height, int offsetLeft, int offsetTop) {
|
||||||
// TODO: implement createWindow
|
// TODO: implement createWindow
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user