From ba3636a203e059cb07bd6ed64226dd0307fe9d18 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Tue, 17 Dec 2024 14:04:59 +0800 Subject: [PATCH] fix: use render thread methods for grid overlay creation and create ubershader instance --- .../src/ffi/src/thermion_viewer_ffi.dart | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/thermion_dart/lib/src/viewer/src/ffi/src/thermion_viewer_ffi.dart b/thermion_dart/lib/src/viewer/src/ffi/src/thermion_viewer_ffi.dart index 4ac1bbc6..9e57d593 100644 --- a/thermion_dart/lib/src/viewer/src/ffi/src/thermion_viewer_ffi.dart +++ b/thermion_dart/lib/src/viewer/src/ffi/src/thermion_viewer_ffi.dart @@ -1760,13 +1760,18 @@ class ThermionViewerFFI extends ThermionViewer { /// /// Future showGridOverlay({FFIMaterial? material}) async { - late Pointer ptr; - if (material == null) { - ptr = SceneManager_createGrid(_sceneManager!, nullptr); - } else { - ptr = SceneManager_createGrid(_sceneManager!, material.pointer); + if (_grid == null) { + final ptr = await withPointerCallback((cb) { + if (material == null) { + SceneManager_createGridRenderThread(_sceneManager!, nullptr, cb); + } else { + SceneManager_createGridRenderThread( + _sceneManager!, material.pointer, cb); + } + }); + _grid = + FFIAsset(ptr, _sceneManager!, _engine!, _unlitMaterialProvider!); } - _grid ??= FFIAsset(ptr, _sceneManager!, _engine!, _unlitMaterialProvider!); await _grid!.addToScene(); } @@ -1913,8 +1918,10 @@ class ThermionViewerFFI extends ThermionViewer { key.hasIOR = hasIOR; key.hasVolume = hasVolume; - final materialInstance = MaterialProvider_createMaterialInstance( - _ubershaderMaterialProvider!, key.address); + final materialInstance = await withPointerCallback((cb) { + MaterialProvider_createMaterialInstanceRenderThread( + _ubershaderMaterialProvider!, key.address, cb); + }); if (materialInstance == nullptr) { throw Exception("Failed to create material instance"); }