Skip to content

Commit

Permalink
Fix crash when reloading tileset
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Aug 18, 2023
1 parent 491ca86 commit 35e8231
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/include/cesium/omniverse/FabricResourceManager.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <omni/fabric/IPath.h>
#include <pxr/usd/sdf/assetPath.h>
#include <pxr/usd/sdf/path.h>

Expand Down Expand Up @@ -86,6 +87,7 @@ class FabricResourceManager {
std::shared_ptr<FabricMaterialPool>
createMaterialPool(const FabricMaterialDefinition& materialDefinition, long stageId);
std::shared_ptr<FabricTexturePool> createTexturePool();
void retainPath(const omni::fabric::Path& path);

int64_t getNextGeometryId();
int64_t getNextMaterialId();
Expand Down Expand Up @@ -117,6 +119,8 @@ class FabricResourceManager {

std::unique_ptr<omni::ui::DynamicTextureProvider> _defaultTexture;
pxr::TfToken _defaultTextureAssetPathToken;

std::vector<omni::fabric::Path> _retainedPaths;
};

} // namespace cesium::omniverse
14 changes: 14 additions & 0 deletions src/core/src/FabricResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ std::shared_ptr<FabricGeometry> 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<FabricGeometry>(path, geometryDefinition, _debugRandomColors, stageId);
}

Expand All @@ -79,6 +80,8 @@ std::shared_ptr<FabricGeometry> FabricResourceManager::acquireGeometry(

auto geometry = geometryPool->acquire();

retainPath(geometry->getPath());

return geometry;
}
std::shared_ptr<FabricMaterial>
Expand All @@ -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<FabricMaterial>(path, materialDefinition, _defaultTextureAssetPathToken, stageId);
}

Expand All @@ -101,6 +105,8 @@ FabricResourceManager::acquireMaterial(const MaterialInfo& materialInfo, bool ha

auto material = materialPool->acquire();

retainPath(material->getPath());

return material;
}

Expand Down Expand Up @@ -268,6 +274,14 @@ std::shared_ptr<FabricTexturePool> FabricResourceManager::createTexturePool() {
std::make_shared<FabricTexturePool>(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++;
}
Expand Down

0 comments on commit 35e8231

Please sign in to comment.