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 8552aa1 commit d770b55
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
5 changes: 5 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 @@ -70,6 +71,8 @@ class FabricResourceManager {
void setTexturePoolInitialCapacity(uint64_t texturePoolInitialCapacity);
void setDebugRandomColors(bool debugRandomColors);

void retainPath(const omni::fabric::Path& path);

void clear();

protected:
Expand Down Expand Up @@ -117,6 +120,8 @@ class FabricResourceManager {

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

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

} // namespace cesium::omniverse
3 changes: 3 additions & 0 deletions src/core/src/FabricGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "cesium/omniverse/FabricAttributesBuilder.h"
#include "cesium/omniverse/FabricMaterial.h"
#include "cesium/omniverse/FabricResourceManager.h"
#include "cesium/omniverse/FabricUtil.h"
#include "cesium/omniverse/GltfUtil.h"
#include "cesium/omniverse/Tokens.h"
Expand Down Expand Up @@ -46,6 +47,8 @@ FabricGeometry::FabricGeometry(
return;
}

FabricResourceManager::getInstance().retainPath(path);

initialize();
reset();
}
Expand Down
11 changes: 8 additions & 3 deletions src/core/src/FabricMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "cesium/omniverse/Context.h"
#include "cesium/omniverse/FabricAttributesBuilder.h"
#include "cesium/omniverse/FabricResourceManager.h"
#include "cesium/omniverse/FabricUtil.h"
#include "cesium/omniverse/Tokens.h"
#include "cesium/omniverse/UsdUtil.h"
Expand Down Expand Up @@ -67,15 +68,19 @@ void FabricMaterial::initialize() {
const auto shaderPath = FabricUtil::joinPaths(materialPath, FabricTokens::Shader);
const auto baseColorTexturePath = FabricUtil::joinPaths(materialPath, FabricTokens::baseColorTexture);

createMaterial(materialPath);
_materialPath = materialPath;
_shaderPath = shaderPath;
_baseColorTexturePath = baseColorTexturePath;

FabricResourceManager::getInstance().retainPath(materialPath);
FabricResourceManager::getInstance().retainPath(shaderPath);
FabricResourceManager::getInstance().retainPath(baseColorTexturePath);

createMaterial(materialPath);
createShader(shaderPath, materialPath);
_shaderPath = shaderPath;

if (hasBaseColorTexture) {
createTexture(baseColorTexturePath, shaderPath, FabricTokens::inputs_base_color_texture);
_baseColorTexturePath = baseColorTexturePath;
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/core/src/FabricResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,15 @@ 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 a future Kit release at which point we can remove
// this workaround.
_retainedPaths.push_back(path);
}

int64_t FabricResourceManager::getNextGeometryId() {
return _geometryId++;
}
Expand Down

0 comments on commit d770b55

Please sign in to comment.