throw exception if concurrent resizes found

This commit is contained in:
Nick Fisher
2024-06-01 12:29:35 +08:00
parent 68160c6bef
commit 5db72f15ea

View File

@@ -51,14 +51,6 @@ class FlutterFilamentFFI extends FlutterFilamentPlatform {
driver: driverPtr, driver: driverPtr,
sharedContext: sharedContextPtr, sharedContext: sharedContextPtr,
uberArchivePath: uberArchivePath); uberArchivePath: uberArchivePath);
// var plugin = FlutterFilamentFFI._(channel,
// renderCallback: renderCallback,
// renderCallbackOwner: renderCallbackOwner,
// resourceLoader: resourceLoader,
// driver: driverPtr,
// sharedContext: sharedContextPtr,
// uberArchivePath: uberArchivePath);
} }
Future<FlutterFilamentTexture?> createTexture( Future<FlutterFilamentTexture?> createTexture(
@@ -74,7 +66,9 @@ class FlutterFilamentFFI extends FlutterFilamentPlatform {
FlutterFilamentTexture(result[0], result[1], width, height, result[2]); FlutterFilamentTexture(result[0], result[1], width, height, result[2]);
await viewer.createSwapChain(width.toDouble(), height.toDouble(), await viewer.createSwapChain(width.toDouble(), height.toDouble(),
surface: texture.surfaceAddress == null ? nullptr : Pointer<Void>.fromAddress(texture.surfaceAddress!)); surface: texture.surfaceAddress == null
? nullptr
: Pointer<Void>.fromAddress(texture.surfaceAddress!));
if (texture.hardwareTextureId != null) { if (texture.hardwareTextureId != null) {
var renderTarget = await viewer.createRenderTarget( var renderTarget = await viewer.createRenderTarget(
@@ -90,41 +84,59 @@ class FlutterFilamentFFI extends FlutterFilamentPlatform {
await _channel.invokeMethod("destroyTexture", texture.flutterTextureId); await _channel.invokeMethod("destroyTexture", texture.flutterTextureId);
} }
bool _resizing = false;
@override @override
Future<FlutterFilamentTexture?> resizeTexture(FlutterFilamentTexture texture, Future<FlutterFilamentTexture?> resizeTexture(FlutterFilamentTexture texture,
int width, int height, int offsetLeft, int offsetRight) async { int width, int height, int offsetLeft, int offsetRight) async {
if (_resizing) {
throw Exception("Resize underway");
}
if ((width - viewer.viewportDimensions.$1).abs() < 0.001 || if ((width - viewer.viewportDimensions.$1).abs() < 0.001 ||
(height - viewer.viewportDimensions.$2).abs() < 0.001) { (height - viewer.viewportDimensions.$2).abs() < 0.001) {
return texture; return texture;
} }
_resizing = true;
bool wasRendering = viewer.rendering; bool wasRendering = viewer.rendering;
await viewer.setRendering(false); await viewer.setRendering(false);
await viewer.destroySwapChain(); await viewer.destroySwapChain();
print("Destoryign texture");
await destroyTexture(texture); await destroyTexture(texture);
print("DEstrooyed!");
var newTexture = var result = await _channel
await createTexture(width, height, offsetLeft, offsetRight); .invokeMethod("createTexture", [width, height, offsetLeft, offsetLeft]);
if (newTexture == null || newTexture.flutterTextureId == -1) {
if (result == null || result[0] == -1) {
throw Exception("Failed to create texture"); throw Exception("Failed to create texture");
} }
await viewer.createSwapChain(width.toDouble(), height.toDouble(), viewer.viewportDimensions = (width.toDouble(), height.toDouble());
surface: Pointer<Void>.fromAddress(newTexture.surfaceAddress!)); var newTexture =
FlutterFilamentTexture(result[0], result[1], width, height, result[2]);
if (newTexture!.hardwareTextureId != null) { await viewer.createSwapChain(width.toDouble(), height.toDouble(),
await viewer.createRenderTarget( surface: newTexture.surfaceAddress == null
width.toDouble(), height.toDouble(), newTexture!.hardwareTextureId!); ? nullptr
: Pointer<Void>.fromAddress(newTexture.surfaceAddress!));
if (newTexture.hardwareTextureId != null) {
var renderTarget = await viewer.createRenderTarget(
width.toDouble(), height.toDouble(), newTexture.hardwareTextureId!);
} }
await viewer.updateViewportAndCameraProjection( await viewer.updateViewportAndCameraProjection(
width.toDouble(), height.toDouble()); width.toDouble(), height.toDouble());
viewer.viewportDimensions = (width.toDouble(), height.toDouble()); viewer.viewportDimensions = (width.toDouble(), height.toDouble());
if (wasRendering) { if (wasRendering) {
await viewer.setRendering(true); await viewer.setRendering(true);
} }
_resizing = false;
return newTexture; return newTexture;
// await _channel.invokeMethod("resizeTexture", // await _channel.invokeMethod("resizeTexture",
// [texture.flutterTextureId, width, height, offsetLeft, offsetRight]); // [texture.flutterTextureId, width, height, offsetLeft, offsetRight]);
} }
@override @override
void dispose() { void dispose() {
// TODO: implement dispose // TODO: implement dispose