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

Fixes an issue on layer editor when trying to save a root layer directly (by right clicking on the layer and Save As.), where an invalid extension could cause a crash. The fallback is .usd. #2847

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 14 additions & 9 deletions lib/mayaUsd/utils/utilSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,8 @@ SdfLayerRefPtr saveAnonymousLayer(
return nullptr;
}

std::string filePath(path);
const std::string& extension = SdfFileFormat::GetFileExtension(filePath);
const std::string defaultExt(UsdMayaTranslatorTokens->UsdFileExtensionDefault.GetText());
const std::string usdCrateExt(UsdMayaTranslatorTokens->UsdFileExtensionCrate.GetText());
const std::string usdASCIIExt(UsdMayaTranslatorTokens->UsdFileExtensionASCII.GetText());
if (extension != defaultExt && extension != usdCrateExt && extension != usdASCIIExt) {
filePath.append(".");
filePath.append(defaultExt.c_str());
}
std::string filePath(path);
ensureUSDFileExtension(filePath);

saveLayerWithFormat(anonLayer, filePath, formatArg);

Expand All @@ -313,6 +306,18 @@ SdfLayerRefPtr saveAnonymousLayer(
return newLayer;
}

void ensureUSDFileExtension(std::string& filePath)
{
const std::string& extension = SdfFileFormat::GetFileExtension(filePath);
const std::string defaultExt(UsdMayaTranslatorTokens->UsdFileExtensionDefault.GetText());
const std::string usdCrateExt(UsdMayaTranslatorTokens->UsdFileExtensionCrate.GetText());
const std::string usdASCIIExt(UsdMayaTranslatorTokens->UsdFileExtensionASCII.GetText());
if (extension != defaultExt && extension != usdCrateExt && extension != usdASCIIExt) {
filePath.append(".");
filePath.append(defaultExt.c_str());
}
}

void getLayersToSaveFromProxy(const std::string& proxyPath, stageLayersToSave& layersInfo)
{
auto stage = UsdMayaUtil::GetStageByProxyName(proxyPath);
Expand Down
7 changes: 6 additions & 1 deletion lib/mayaUsd/utils/utilSerialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ PXR_NS::SdfLayerRefPtr saveAnonymousLayer(
LayerParent parent,
std::string formatArg = "");

/*! \brief Check the sublayer stack of the stage looking for any anonymnous
/*! \brief Ensures that the filepath contains a valid USD extension.
*/
MAYAUSD_CORE_PUBLIC
void ensureUSDFileExtension(std::string& filePath);

/*! \brief Check the sublayer stack of the stage looking for any anonymous
layers that will need to be saved.
*/
MAYAUSD_CORE_PUBLIC
Expand Down
5 changes: 4 additions & 1 deletion lib/usd/ui/layerEditor/layerTreeItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,10 @@ void LayerTreeItem::saveAnonymousLayer()

std::string fileName;
if (sessionState->saveLayerUI(nullptr, &fileName)) {
// the path we has is an absolute path

MayaUsd::utils::ensureUSDFileExtension(fileName);

// the path we have is an absolute path
const QString dialogTitle = StringResources::getAsQString(StringResources::kSaveLayer);
std::string formatTag = MayaUsd::utils::usdFormatArgOption();
if (saveSubLayer(dialogTitle, parentLayerItem(), layer(), fileName, formatTag)) {
Expand Down