Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when dependent prims are removed in specific order #680

Merged
merged 7 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/core/include/cesium/omniverse/UsdUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ Cesium3DTilesSelection::ViewState computeViewState(
const Viewport& viewport);

bool primExists(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
bool isSchemaValid(const pxr::UsdSchemaBase& schema);

bool isPrimVisible(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
const std::string& getName(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);

Expand Down
3 changes: 3 additions & 0 deletions src/core/src/OmniCartographicPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ std::vector<CesiumGeospatial::Cartographic> OmniCartographicPolygon::getCartogra
}

const auto cesiumCartographicPolygon = UsdUtil::getCesiumCartographicPolygon(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumCartographicPolygon)) {
return {};
}

pxr::VtArray<pxr::GfVec3f> points;
cesiumCartographicPolygon.GetPointsAttr().Get(&points);
Expand Down
33 changes: 33 additions & 0 deletions src/core/src/OmniData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const pxr::SdfPath& OmniData::getPath() const {

pxr::SdfPath OmniData::getSelectedIonServerPath() const {
const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumData)) {
return {};
}

pxr::SdfPathVector targets;
cesiumData.GetSelectedIonServerRel().GetForwardedTargets(&targets);
Expand All @@ -30,6 +33,9 @@ pxr::SdfPath OmniData::getSelectedIonServerPath() const {

bool OmniData::getDebugDisableMaterials() const {
const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumData)) {
return false;
}

bool disableMaterials;
cesiumData.GetDebugDisableMaterialsAttr().Get(&disableMaterials);
Expand All @@ -39,6 +45,9 @@ bool OmniData::getDebugDisableMaterials() const {

bool OmniData::getDebugDisableTextures() const {
const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumData)) {
return false;
}

bool disableTextures;
cesiumData.GetDebugDisableTexturesAttr().Get(&disableTextures);
Expand All @@ -48,6 +57,9 @@ bool OmniData::getDebugDisableTextures() const {

bool OmniData::getDebugDisableGeometryPool() const {
const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumData)) {
return false;
}

bool disableGeometryPool;
cesiumData.GetDebugDisableGeometryPoolAttr().Get(&disableGeometryPool);
Expand All @@ -57,6 +69,9 @@ bool OmniData::getDebugDisableGeometryPool() const {

bool OmniData::getDebugDisableMaterialPool() const {
const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumData)) {
return false;
}

bool disableMaterialPool;
cesiumData.GetDebugDisableMaterialPoolAttr().Get(&disableMaterialPool);
Expand All @@ -66,6 +81,9 @@ bool OmniData::getDebugDisableMaterialPool() const {

bool OmniData::getDebugDisableTexturePool() const {
const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumData)) {
return false;
}

bool disableTexturePool;
cesiumData.GetDebugDisableTexturePoolAttr().Get(&disableTexturePool);
Expand All @@ -75,6 +93,9 @@ bool OmniData::getDebugDisableTexturePool() const {

uint64_t OmniData::getDebugGeometryPoolInitialCapacity() const {
const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumData)) {
return 2048;
}

uint64_t geometryPoolInitialCapacity;
cesiumData.GetDebugGeometryPoolInitialCapacityAttr().Get(&geometryPoolInitialCapacity);
Expand All @@ -84,6 +105,9 @@ uint64_t OmniData::getDebugGeometryPoolInitialCapacity() const {

uint64_t OmniData::getDebugMaterialPoolInitialCapacity() const {
const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumData)) {
return 2048;
}

uint64_t materialPoolInitialCapacity;
cesiumData.GetDebugMaterialPoolInitialCapacityAttr().Get(&materialPoolInitialCapacity);
Expand All @@ -93,6 +117,9 @@ uint64_t OmniData::getDebugMaterialPoolInitialCapacity() const {

uint64_t OmniData::getDebugTexturePoolInitialCapacity() const {
const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumData)) {
return 2048;
}

uint64_t texturePoolInitialCapacity;
cesiumData.GetDebugTexturePoolInitialCapacityAttr().Get(&texturePoolInitialCapacity);
Expand All @@ -102,6 +129,9 @@ uint64_t OmniData::getDebugTexturePoolInitialCapacity() const {

bool OmniData::getDebugRandomColors() const {
const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumData)) {
return false;
}

bool debugRandomColors;
cesiumData.GetDebugRandomColorsAttr().Get(&debugRandomColors);
Expand All @@ -111,6 +141,9 @@ bool OmniData::getDebugRandomColors() const {

bool OmniData::getDebugDisableGeoreferencing() const {
const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumData)) {
return false;
}

bool debugDisableGeoreferencing;
cesiumData.GetDebugDisableGeoreferencingAttr().Get(&debugDisableGeoreferencing);
Expand Down
3 changes: 3 additions & 0 deletions src/core/src/OmniGeoreference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const pxr::SdfPath& OmniGeoreference::getPath() const {

CesiumGeospatial::Cartographic OmniGeoreference::getOrigin() const {
const auto cesiumGeoreference = UsdUtil::getCesiumGeoreference(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumGeoreference)) {
return {0.0, 0.0, 0.0};
}

double longitude;
double latitude;
Expand Down
64 changes: 55 additions & 9 deletions src/core/src/OmniGlobeAnchor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ const pxr::SdfPath& OmniGlobeAnchor::getPath() const {

bool OmniGlobeAnchor::getDetectTransformChanges() const {
const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumGlobeAnchor)) {
return true;
}

bool detectTransformChanges;
cesiumGlobeAnchor.GetDetectTransformChangesAttr().Get(&detectTransformChanges);
Expand All @@ -58,6 +61,9 @@ bool OmniGlobeAnchor::getDetectTransformChanges() const {

bool OmniGlobeAnchor::getAdjustOrientation() const {
const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumGlobeAnchor)) {
return true;
}

bool adjustOrientation;
cesiumGlobeAnchor.GetAdjustOrientationForGlobeWhenMovingAttr().Get(&adjustOrientation);
Expand All @@ -67,6 +73,9 @@ bool OmniGlobeAnchor::getAdjustOrientation() const {

pxr::SdfPath OmniGlobeAnchor::getResolvedGeoreferencePath() const {
const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumGlobeAnchor)) {
return {};
}

pxr::SdfPathVector targets;
cesiumGlobeAnchor.GetGeoreferenceBindingRel().GetForwardedTargets(&targets);
Expand Down Expand Up @@ -158,7 +167,7 @@ void OmniGlobeAnchor::updateByPrimLocalTransform(bool resetOrientation) {
}

const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path);
const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor.GetPrim());
const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor);
const auto xformOps = UsdUtil::getOrCreateTranslateRotateScaleOps(xformable);
const auto eulerAngleOrder = xformOps->eulerAngleOrder;

Expand Down Expand Up @@ -202,7 +211,11 @@ bool OmniGlobeAnchor::isAnchorValid() const {
}

const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path);
const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor.GetPrim());
const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor);
if (!UsdUtil::isSchemaValid(xformable)) {
return false;
}

const auto xformOps = UsdUtil::getOrCreateTranslateRotateScaleOps(xformable);

if (!xformOps) {
Expand All @@ -229,7 +242,10 @@ void OmniGlobeAnchor::initialize() {
// when using globe anchors.

const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path);
const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor.GetPrim());
const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor);
if (!UsdUtil::isSchemaValid(xformable)) {
return;
}

bool resetsXformStack;
const auto originalXformOps = xformable.GetOrderedXformOps(&resetsXformStack);
Expand Down Expand Up @@ -268,6 +284,9 @@ void OmniGlobeAnchor::finalize() {

glm::dvec3 OmniGlobeAnchor::getPrimLocalToEcefTranslation() const {
const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumGlobeAnchor)) {
return {0.0, 0.0, 0.0};
}

pxr::GfVec3d primLocalToEcefTranslation;
cesiumGlobeAnchor.GetPositionAttr().Get(&primLocalToEcefTranslation);
Expand All @@ -277,6 +296,9 @@ glm::dvec3 OmniGlobeAnchor::getPrimLocalToEcefTranslation() const {

CesiumGeospatial::Cartographic OmniGlobeAnchor::getGeographicCoordinates() const {
const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumGlobeAnchor)) {
return {0.0, 0.0, 0.0};
}

double longitude;
double latitude;
Expand All @@ -291,36 +313,57 @@ CesiumGeospatial::Cartographic OmniGlobeAnchor::getGeographicCoordinates() const

glm::dvec3 OmniGlobeAnchor::getPrimLocalTranslation() const {
const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path);
const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor.GetPrim());
const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor);
if (!UsdUtil::isSchemaValid(xformable)) {
return {0.0, 0.0, 0.0};
}

const auto xformOps = UsdUtil::getOrCreateTranslateRotateScaleOps(xformable);
return UsdUtil::getTranslate(xformOps.value().translateOp);
}

glm::dvec3 OmniGlobeAnchor::getPrimLocalRotation() const {
const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path);
const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor.GetPrim());
const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor);
if (!UsdUtil::isSchemaValid(xformable)) {
return {0.0, 0.0, 0.0};
}

const auto xformOps = UsdUtil::getOrCreateTranslateRotateScaleOps(xformable);
return glm::radians(UsdUtil::getRotate(xformOps.value().rotateOp));
}

glm::dvec3 OmniGlobeAnchor::getPrimLocalScale() const {
const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path);
const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor.GetPrim());
const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor);
if (!UsdUtil::isSchemaValid(xformable)) {
return {1.0, 1.0, 1.0};
}

const auto xformOps = UsdUtil::getOrCreateTranslateRotateScaleOps(xformable);
return UsdUtil::getScale(xformOps.value().scaleOp);
}

void OmniGlobeAnchor::savePrimLocalToEcefTranslation() {
const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumGlobeAnchor)) {
return;
}

const auto& primLocalToEcefTransform = _pAnchor->getAnchorToFixedTransform();
const auto primLocalToEcefTranslation = glm::dvec3(primLocalToEcefTransform[3]);

_cachedPrimLocalToEcefTranslation = primLocalToEcefTranslation;

const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path);
cesiumGlobeAnchor.GetPositionAttr().Set(UsdUtil::glmToUsdVector(primLocalToEcefTranslation));
}

void OmniGlobeAnchor::saveGeographicCoordinates() {
const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumGlobeAnchor)) {
return;
}

const auto pGeoreference = _pContext->getAssetRegistry().getGeoreference(getResolvedGeoreferencePath());
const auto& primLocalToEcefTransform = _pAnchor->getAnchorToFixedTransform();
const auto primLocalToEcefTranslation = glm::dvec3(primLocalToEcefTransform[3]);
Expand All @@ -332,7 +375,6 @@ void OmniGlobeAnchor::saveGeographicCoordinates() {

_cachedGeographicCoordinates = *cartographic;

const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path);
cesiumGlobeAnchor.GetAnchorLongitudeAttr().Set(glm::degrees(cartographic->longitude));
cesiumGlobeAnchor.GetAnchorLatitudeAttr().Set(glm::degrees(cartographic->latitude));
cesiumGlobeAnchor.GetAnchorHeightAttr().Set(cartographic->height);
Expand All @@ -343,7 +385,11 @@ void OmniGlobeAnchor::savePrimLocalTransform() {
// work when rotation and scale properties are double precision, which is common in Omniverse.

const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path);
const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor.GetPrim());
const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor);
if (!UsdUtil::isSchemaValid(xformable)) {
return;
}

auto xformOps = UsdUtil::getOrCreateTranslateRotateScaleOps(xformable);

auto& [translateOp, rotateOp, scaleOp, eulerAngleOrder] = xformOps.value();
Expand Down
9 changes: 9 additions & 0 deletions src/core/src/OmniIonRasterOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ OmniIonRasterOverlay::OmniIonRasterOverlay(Context* pContext, const pxr::SdfPath

int64_t OmniIonRasterOverlay::getIonAssetId() const {
const auto cesiumIonRasterOverlay = UsdUtil::getCesiumIonRasterOverlay(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumIonRasterOverlay)) {
return 0;
}

int64_t ionAssetId;
cesiumIonRasterOverlay.GetIonAssetIdAttr().Get(&ionAssetId);
Expand All @@ -34,6 +37,9 @@ int64_t OmniIonRasterOverlay::getIonAssetId() const {

CesiumIonClient::Token OmniIonRasterOverlay::getIonAccessToken() const {
const auto cesiumIonRasterOverlay = UsdUtil::getCesiumIonRasterOverlay(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumIonRasterOverlay)) {
return {};
}

std::string ionAccessToken;
cesiumIonRasterOverlay.GetIonAccessTokenAttr().Get(&ionAccessToken);
Expand Down Expand Up @@ -77,6 +83,9 @@ std::string OmniIonRasterOverlay::getIonApiUrl() const {

pxr::SdfPath OmniIonRasterOverlay::getResolvedIonServerPath() const {
const auto cesiumIonRasterOverlay = UsdUtil::getCesiumIonRasterOverlay(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumIonRasterOverlay)) {
return {};
}

pxr::SdfPathVector targets;
cesiumIonRasterOverlay.GetIonServerBindingRel().GetForwardedTargets(&targets);
Expand Down
15 changes: 15 additions & 0 deletions src/core/src/OmniIonServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ std::shared_ptr<CesiumIonSession> OmniIonServer::getSession() const {

std::string OmniIonServer::getIonServerUrl() const {
const auto cesiumIonServer = UsdUtil::getCesiumIonServer(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumIonServer)) {
return "";
}

std::string ionServerUrl;
cesiumIonServer.GetIonServerUrlAttr().Get(&ionServerUrl);
Expand All @@ -38,6 +41,9 @@ std::string OmniIonServer::getIonServerUrl() const {

std::string OmniIonServer::getIonServerApiUrl() const {
const auto cesiumIonServer = UsdUtil::getCesiumIonServer(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumIonServer)) {
return "";
}

std::string ionServerApiUrl;
cesiumIonServer.GetIonServerApiUrlAttr().Get(&ionServerApiUrl);
Expand All @@ -47,6 +53,9 @@ std::string OmniIonServer::getIonServerApiUrl() const {

int64_t OmniIonServer::getIonServerApplicationId() const {
const auto cesiumIonServer = UsdUtil::getCesiumIonServer(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumIonServer)) {
return 0;
}

int64_t ionServerApplicationId;
cesiumIonServer.GetIonServerApplicationIdAttr().Get(&ionServerApplicationId);
Expand All @@ -56,6 +65,9 @@ int64_t OmniIonServer::getIonServerApplicationId() const {

CesiumIonClient::Token OmniIonServer::getToken() const {
const auto cesiumIonServer = UsdUtil::getCesiumIonServer(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumIonServer)) {
return {};
}

std::string projectDefaultIonAccessToken;
std::string projectDefaultIonAccessTokenId;
Expand All @@ -72,6 +84,9 @@ CesiumIonClient::Token OmniIonServer::getToken() const {

void OmniIonServer::setToken(const CesiumIonClient::Token& token) {
const auto cesiumIonServer = UsdUtil::getCesiumIonServer(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumIonServer)) {
return;
}

cesiumIonServer.GetProjectDefaultIonAccessTokenAttr().Set(token.token);
cesiumIonServer.GetProjectDefaultIonAccessTokenIdAttr().Set(token.id);
Expand Down
Loading
Loading