From 35e823190e3825557b0b581a0057c072ee94033a Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Fri, 18 Aug 2023 10:13:28 -0400 Subject: [PATCH] Fix crash when reloading tileset --- .../cesium/omniverse/FabricResourceManager.h | 4 ++++ src/core/src/FabricResourceManager.cpp | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/core/include/cesium/omniverse/FabricResourceManager.h b/src/core/include/cesium/omniverse/FabricResourceManager.h index 6808e7872..f51d4bf31 100644 --- a/src/core/include/cesium/omniverse/FabricResourceManager.h +++ b/src/core/include/cesium/omniverse/FabricResourceManager.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -86,6 +87,7 @@ class FabricResourceManager { std::shared_ptr createMaterialPool(const FabricMaterialDefinition& materialDefinition, long stageId); std::shared_ptr createTexturePool(); + void retainPath(const omni::fabric::Path& path); int64_t getNextGeometryId(); int64_t getNextMaterialId(); @@ -117,6 +119,8 @@ class FabricResourceManager { std::unique_ptr _defaultTexture; pxr::TfToken _defaultTextureAssetPathToken; + + std::vector _retainedPaths; }; } // namespace cesium::omniverse diff --git a/src/core/src/FabricResourceManager.cpp b/src/core/src/FabricResourceManager.cpp index 76f1f8ab4..864eb8c0c 100644 --- a/src/core/src/FabricResourceManager.cpp +++ b/src/core/src/FabricResourceManager.cpp @@ -66,6 +66,7 @@ std::shared_ptr FabricResourceManager::acquireGeometry( if (_disableGeometryPool) { const auto pathStr = fmt::format("/fabric_geometry_{}", getNextGeometryId()); const auto path = omni::fabric::Path(pathStr.c_str()); + retainPath(path); return std::make_shared(path, geometryDefinition, _debugRandomColors, stageId); } @@ -79,6 +80,8 @@ std::shared_ptr FabricResourceManager::acquireGeometry( auto geometry = geometryPool->acquire(); + retainPath(geometry->getPath()); + return geometry; } std::shared_ptr @@ -88,6 +91,7 @@ FabricResourceManager::acquireMaterial(const MaterialInfo& materialInfo, bool ha if (_disableMaterialPool) { const auto pathStr = fmt::format("/fabric_material_{}", getNextMaterialId()); const auto path = omni::fabric::Path(pathStr.c_str()); + retainPath(path); return std::make_shared(path, materialDefinition, _defaultTextureAssetPathToken, stageId); } @@ -101,6 +105,8 @@ FabricResourceManager::acquireMaterial(const MaterialInfo& materialInfo, bool ha auto material = materialPool->acquire(); + retainPath(material->getPath()); + return material; } @@ -268,6 +274,14 @@ std::shared_ptr FabricResourceManager::createTexturePool() { std::make_shared(getNextPoolId(), _texturePoolInitialCapacity)); } +void FabricResourceManager::retainPath(const omni::fabric::Path& path) { + // This is a workaround for https://github.com/CesiumGS/cesium-omniverse/issues/425. + // By retaining a reference to the path we avoid a crash deep in the Sdf library + // that's triggered by loading a tileset, removing the tileset, and reloading the tileset. + // It's possible this will be fixed in future Kit releases. + _retainedPaths.push_back(path); +} + int64_t FabricResourceManager::getNextGeometryId() { return _geometryId++; }