Skip to content

Commit e232df3

Browse files
committed
Improve error message in Archive
Signed-off-by: Dan Bailey <danbailey@ilm.com>
1 parent bd2e735 commit e232df3

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

openvdb/openvdb/io/Archive.cc

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,17 @@ Archive::readGrid(const GridDescriptor& gd, std::istream& is, const io::ReadOpti
973973
}
974974
grid->setSaveFloatAsHalf(gd.saveFloatAsHalf());
975975

976+
#ifndef OPENVDB_ENABLE_TREE_IO
977+
if (!codec) {
978+
OPENVDB_THROW(IoError,
979+
"No I/O codec found for " << gd.gridType() << ", "
980+
<< "register the codec for this grid type "
981+
<< "(either explicitly or via openvdb::initialize()). "
982+
<< "Note: Tree I/O is deprecated, "
983+
<< "but can be re-enabled by recompiling with CMake OPENVDB_ENABLE_TREE_IO=ON.");
984+
}
985+
#endif
986+
976987
// Stream metadata varies per grid, and it needs to persist
977988
// in case delayed load is in effect.
978989
io::StreamMetadata::Ptr streamMetadata;
@@ -1007,8 +1018,6 @@ Archive::readGrid(const GridDescriptor& gd, std::istream& is, const io::ReadOpti
10071018
} else {
10081019
#ifdef OPENVDB_ENABLE_TREE_IO
10091020
grid->readTopology(is);
1010-
#else
1011-
OPENVDB_THROW(IoError, "Tree I/O functionality is not enabled");
10121021
#endif
10131022
}
10141023
// read buffers
@@ -1024,8 +1033,6 @@ Archive::readGrid(const GridDescriptor& gd, std::istream& is, const io::ReadOpti
10241033
} else {
10251034
grid->readBuffers(is);
10261035
}
1027-
#else
1028-
OPENVDB_THROW(IoError, "Tree I/O functionality is not enabled");
10291036
#endif
10301037
}
10311038
}
@@ -1166,6 +1173,17 @@ Archive::writeGrid(GridDescriptor& gd, GridBase::ConstPtr grid,
11661173
// Find the codec for the grid type and options.
11671174
io::Codec* codec = findCodec(gd.gridType());
11681175

1176+
#ifndef OPENVDB_ENABLE_TREE_IO
1177+
if (!codec) {
1178+
OPENVDB_THROW(IoError,
1179+
"No I/O codec found for " << gd.gridType() << ", "
1180+
<< "register the codec for this grid type "
1181+
<< "(either explicitly or via openvdb::initialize()). "
1182+
<< "Note: Tree I/O is deprecated, "
1183+
<< "but can be re-enabled by recompiling with CMake OPENVDB_ENABLE_TREE_IO=ON.");
1184+
}
1185+
#endif
1186+
11691187
// Stream metadata varies per grid, so make a copy of the file-level stream metadata.
11701188
io::StreamMetadata::Ptr streamMetadata;
11711189
if (io::StreamMetadata::Ptr meta = io::getStreamMetadataPtr(os)) {
@@ -1214,8 +1232,6 @@ Archive::writeGrid(GridDescriptor& gd, GridBase::ConstPtr grid,
12141232
} else {
12151233
#ifdef OPENVDB_ENABLE_TREE_IO
12161234
grid->writeTopology(os);
1217-
#else
1218-
OPENVDB_THROW(IoError, "Tree I/O functionality is not enabled");
12191235
#endif
12201236
}
12211237

@@ -1228,8 +1244,6 @@ Archive::writeGrid(GridDescriptor& gd, GridBase::ConstPtr grid,
12281244
} else {
12291245
#ifdef OPENVDB_ENABLE_TREE_IO
12301246
grid->writeBuffers(os);
1231-
#else
1232-
OPENVDB_THROW(IoError, "Tree I/O functionality is not enabled");
12331247
#endif
12341248
}
12351249

0 commit comments

Comments
 (0)