Skip to content

Commit f648d2b

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

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

openvdb/openvdb/io/Archive.cc

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,17 @@ Archive::readGrid(const GridDescriptor& gd, std::istream& is, const io::ReadOpti
977977
}
978978
grid->setSaveFloatAsHalf(gd.saveFloatAsHalf());
979979

980+
#ifndef OPENVDB_ENABLE_TREE_IO
981+
if (!codec) {
982+
OPENVDB_THROW(IoError,
983+
"No I/O codec found for " << gd.gridType() << ", "
984+
<< "register the codec for this grid type "
985+
<< "(either explicitly or via openvdb::initialize()). "
986+
<< "Note: Tree I/O is deprecated, "
987+
<< "but can be re-enabled by recompiling with CMake OPENVDB_ENABLE_TREE_IO=ON.");
988+
}
989+
#endif
990+
980991
// Stream metadata varies per grid, and it needs to persist
981992
// in case delayed load is in effect.
982993
io::StreamMetadata::Ptr streamMetadata;
@@ -1011,8 +1022,6 @@ Archive::readGrid(const GridDescriptor& gd, std::istream& is, const io::ReadOpti
10111022
} else {
10121023
#ifdef OPENVDB_ENABLE_TREE_IO
10131024
grid->readTopology(is);
1014-
#else
1015-
OPENVDB_THROW(IoError, "Tree I/O functionality is not enabled");
10161025
#endif
10171026
}
10181027
// read buffers
@@ -1028,8 +1037,6 @@ Archive::readGrid(const GridDescriptor& gd, std::istream& is, const io::ReadOpti
10281037
} else {
10291038
grid->readBuffers(is);
10301039
}
1031-
#else
1032-
OPENVDB_THROW(IoError, "Tree I/O functionality is not enabled");
10331040
#endif
10341041
}
10351042
}
@@ -1170,6 +1177,15 @@ Archive::writeGrid(GridDescriptor& gd, GridBase::ConstPtr grid,
11701177
// Find the codec for the grid type and options.
11711178
io::Codec* codec = findCodec(gd.gridType());
11721179

1180+
if (!codec) {
1181+
OPENVDB_THROW(IoError,
1182+
"No I/O codec found for " << gd.gridType() << ", "
1183+
<< "register the codec for this grid type "
1184+
<< "(either explicitly or via openvdb::initialize()). "
1185+
<< "Note: Tree I/O is deprecated, "
1186+
<< "but can be re-enabled by recompiling with CMake OPENVDB_ENABLE_TREE_IO=ON.");
1187+
}
1188+
11731189
// Stream metadata varies per grid, so make a copy of the file-level stream metadata.
11741190
io::StreamMetadata::Ptr streamMetadata;
11751191
if (io::StreamMetadata::Ptr meta = io::getStreamMetadataPtr(os)) {
@@ -1218,8 +1234,6 @@ Archive::writeGrid(GridDescriptor& gd, GridBase::ConstPtr grid,
12181234
} else {
12191235
#ifdef OPENVDB_ENABLE_TREE_IO
12201236
grid->writeTopology(os);
1221-
#else
1222-
OPENVDB_THROW(IoError, "Tree I/O functionality is not enabled");
12231237
#endif
12241238
}
12251239

@@ -1232,8 +1246,6 @@ Archive::writeGrid(GridDescriptor& gd, GridBase::ConstPtr grid,
12321246
} else {
12331247
#ifdef OPENVDB_ENABLE_TREE_IO
12341248
grid->writeBuffers(os);
1235-
#else
1236-
OPENVDB_THROW(IoError, "Tree I/O functionality is not enabled");
12371249
#endif
12381250
}
12391251

0 commit comments

Comments
 (0)