Skip to content

Commit 1efbe09

Browse files
authored
Merge pull request #1757 from Idclip/vdb_asserts
Introduce OPENVDB_ASSERT macro to replace cassert usage
2 parents ea5b229 + eb3656c commit 1efbe09

File tree

138 files changed

+1289
-1071
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+1289
-1071
lines changed

CMakeLists.txt

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,42 @@ project(OpenVDB LANGUAGES CXX VERSION ${OpenVDB_VERSION})
6464
include(CMakeDependentOption)
6565
include(GNUInstallDirs)
6666

67-
# todo epydoc and pdflatex
67+
# Components
6868
option(OPENVDB_BUILD_CORE "Enable the core OpenVDB library. Both static and shared versions are enabled by default" ON)
6969
option(OPENVDB_BUILD_BINARIES "Enable the vdb binaries. Only vdb_print is enabled by default" ON)
7070
option(OPENVDB_BUILD_PYTHON_MODULE "Build the pyopenvdb Python module" OFF)
7171
option(OPENVDB_BUILD_UNITTESTS "Build the OpenVDB unit tests" OFF)
7272
option(OPENVDB_BUILD_DOCS "Build the OpenVDB documentation" OFF)
7373
option(OPENVDB_BUILD_HOUDINI_PLUGIN "Build the Houdini plugin" OFF)
7474
option(OPENVDB_BUILD_HOUDINI_ABITESTS "Build the Houdini ABI tests" OFF)
75-
75+
option(OPENVDB_BUILD_MAYA_PLUGIN "Build the Maya plugin" OFF)
7676
option(OPENVDB_BUILD_AX "Build the OpenVDB AX library. Turns ON if USE_AX is ON." ${USE_AX})
7777
option(OPENVDB_BUILD_AX_UNITTESTS "Build the OpenVDB AX unit tests" OFF)
78-
7978
option(OPENVDB_BUILD_NANOVDB "Build the NanoVDB library. Turns ON if USE_NANOVDB is ON." ${USE_NANOVDB})
8079

81-
option(OPENVDB_BUILD_MAYA_PLUGIN "Build the Maya plugin" OFF)
82-
option(OPENVDB_USE_DELAYED_LOADING "Build the core OpenVDB library with delayed-loading." ON)
80+
# Global options
8381
option(OPENVDB_ENABLE_RPATH "Build with RPATH information" ON)
82+
option(OPENVDB_ENABLE_ASSERTS "Build with asserts in OpenVDB code enabled" OFF)
83+
option(OPENVDB_USE_DELAYED_LOADING "Build the core OpenVDB library with delayed-loading." ON)
8484
option(OPENVDB_CXX_STRICT "Enable or disable pre-defined compiler warnings" OFF)
85-
8685
cmake_dependent_option(OPENVDB_INSTALL_CMAKE_MODULES
8786
"Install the provided OpenVDB CMake modules when building the core library"
8887
ON "OPENVDB_BUILD_CORE" OFF)
88+
option(USE_CCACHE "Build using Ccache if found on the path" ON)
89+
# Disable this on Windows due to linker OOM issues:
90+
# LNK1248: image size (XXX) exceeds maximum allowable size (FFFFFFFF)
91+
# https://github.com/AcademySoftwareFoundation/openvdb/issues/1718
92+
# https://github.com/AcademySoftwareFoundation/openvdb/issues/1624
93+
cmake_dependent_option(USE_EXPLICIT_INSTANTIATION "Use explicit instantiation for all supported classes
94+
and methods against a pre-defined list of OpenVDB trees. This makes the core library larger and slower
95+
to compile, but speeds up the compilation of all dependent code by bypassing the expensive template
96+
instantation." ON "NOT WIN32" OFF)
97+
option(OPENVDB_FUTURE_DEPRECATION "Generate messages for upcoming deprecation" ON)
98+
option(OPENVDB_ENABLE_UNINSTALL "Adds a CMake uninstall target." ON)
99+
option(USE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." OFF)
89100

101+
# Component dependency options
102+
cmake_dependent_option(USE_PKGCONFIG "Use pkg-config to search for dependent libraries." ON "NOT WIN32" OFF)
90103
option(USE_HOUDINI [=[
91104
Build the library against a Houdini installation. Turns on automatically if OPENVDB_BUILD_HOUDINI_PLUGIN is enabled.
92105
When enabled, you do not need to provide dependency locations for TBB, Blosc, Imath and OpenEXR. Boost must be
@@ -121,7 +134,6 @@ option(USE_NANOVDB "Use NanoVDB while building openvdb components." ${OPENVDB_BU
121134

122135
cmake_dependent_option(OPENVDB_DISABLE_BOOST_IMPLICIT_LINKING
123136
"Disable the implicit linking of Boost libraries on Windows" ON "WIN32" OFF)
124-
option(USE_CCACHE "Build using Ccache if found on the path" ON)
125137
option(USE_STATIC_DEPENDENCIES [=[
126138
Only search for and use static libraries. If OFF the shared versions of requried libraries are prioritised, falling
127139
back to static libraries. Forcing individual static dependencies can be enabled by setting XXX_USE_STATIC_LIBS
@@ -136,20 +148,6 @@ its default system search routine if it cannot find a dependency with the provid
136148
paths provided through the Xxx_ROOT, supported XXX_INCLUDEDIR/XXX_LIBRARYDIR variables or the SYSTEM_LIBRARY_PATHS
137149
list will be searched.]=] OFF)
138150

139-
option(OPENVDB_FUTURE_DEPRECATION "Generate messages for upcoming deprecation" ON)
140-
option(OPENVDB_ENABLE_UNINSTALL "Adds a CMake uninstall target." ON)
141-
option(USE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." OFF)
142-
cmake_dependent_option(USE_PKGCONFIG "Use pkg-config to search for dependent libraries." ON "NOT WIN32" OFF)
143-
144-
# Disable this on Windows due to linker OOM issues:
145-
# LNK1248: image size (XXX) exceeds maximum allowable size (FFFFFFFF)
146-
# https://github.com/AcademySoftwareFoundation/openvdb/issues/1718
147-
# https://github.com/AcademySoftwareFoundation/openvdb/issues/1624
148-
cmake_dependent_option(USE_EXPLICIT_INSTANTIATION "Use explicit instantiation for all supported classes
149-
and methods against a pre-defined list of OpenVDB trees. This makes the core library larger and slower
150-
to compile, but speeds up the compilation of all dependent code by bypassing the expensive template
151-
instantation." ON "NOT WIN32" OFF)
152-
153151
set(SYSTEM_LIBRARY_PATHS "" CACHE STRING [=[
154152
A global list of library paths to additionally use into when searching for dependencies.]=])
155153
set(MSVC_MP_THREAD_COUNT "" CACHE STRING [=[

ci/build.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,15 @@ if HAS_PARM -v || HAS_PARM --verbose; then
121121
# support older versions of CMake.
122122
CMAKE_EXTRA+=("-DCMAKE_VERBOSE_MAKEFILE=ON")
123123
fi
124-
if HAS_PARM --build-type; then CMAKE_EXTRA+=("-DCMAKE_BUILD_TYPE=${PARMS[--build-type]}"); fi
124+
if HAS_PARM --build-type; then
125+
CMAKE_EXTRA+=("-DCMAKE_BUILD_TYPE=${PARMS[--build-type]}")
126+
build_type="${PARMS[--build-type]}"
127+
debug="Debug"
128+
# Ignore case - if the build-type is Debug, we enable asserts
129+
if [ "${build_type,,}" = "${debug,,}" ]; then
130+
CMAKE_EXTRA+=("-DOPENVDB_ENABLE_ASSERTS=ON")
131+
fi
132+
fi
125133

126134
# Available components. If a component is not provided it is
127135
# explicitly set to OFF.

ci/install_windows.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
set -ex
44

55
vcpkg update
6-
vcpkg install zlib libpng openexr tbb gtest blosc glfw3 glew python3 jemalloc \
6+
vcpkg install zlib libpng openexr tbb gtest cppunit blosc glfw3 glew python3 jemalloc \
77
boost-iostreams boost-interprocess boost-algorithm pybind11 \
88
--clean-after-build

cmake/config/OpenVDBCXX.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
317317
if(NOT _isMultiConfig)
318318
message(STATUS "CMake Build Type: ${CMAKE_BUILD_TYPE}")
319319
endif()
320+
if(OPENVDB_ENABLE_ASSERTS)
321+
message(STATUS "OpenVDB asserts are ENABLED")
322+
endif()
320323

321324
# Intialize extra build type targets where possible
322325

openvdb/openvdb/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ set(OPENVDB_LIBRARY_SOURCE_FILES
375375
points/AttributeSet.cc
376376
points/StreamCompression.cc
377377
points/points.cc
378+
util/Assert.cc
378379
util/Formats.cc
379380
)
380381

@@ -543,6 +544,7 @@ set(OPENVDB_LIBRARY_TREE_INCLUDE_FILES
543544
)
544545

545546
set(OPENVDB_LIBRARY_UTIL_INCLUDE_FILES
547+
util/Assert.h
546548
util/CpuTimer.h
547549
util/ExplicitInstantiation.h
548550
util/Formats.h

openvdb/openvdb/Grid.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#include "io/io.h"
1111
#include "math/Transform.h"
1212
#include "tree/Tree.h"
13+
#include "util/Assert.h"
1314
#include "util/logging.h"
1415
#include "util/Name.h"
15-
#include <cassert>
1616
#include <iostream>
1717
#include <set>
1818
#include <type_traits>
@@ -1610,7 +1610,7 @@ Grid<TreeT>::readBuffers(std::istream& is)
16101610
uint16_t numPasses = 1;
16111611
is.read(reinterpret_cast<char*>(&numPasses), sizeof(uint16_t));
16121612
const io::StreamMetadata::Ptr meta = io::getStreamMetadataPtr(is);
1613-
assert(bool(meta));
1613+
OPENVDB_ASSERT(bool(meta));
16141614
for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
16151615
uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
16161616
meta->setPass(pass);
@@ -1632,7 +1632,7 @@ Grid<TreeT>::readBuffers(std::istream& is, const CoordBBox& bbox)
16321632
uint16_t numPasses = 1;
16331633
is.read(reinterpret_cast<char*>(&numPasses), sizeof(uint16_t));
16341634
const io::StreamMetadata::Ptr meta = io::getStreamMetadataPtr(is);
1635-
assert(bool(meta));
1635+
OPENVDB_ASSERT(bool(meta));
16361636
for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
16371637
uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
16381638
meta->setPass(pass);
@@ -1662,7 +1662,7 @@ Grid<TreeT>::writeBuffers(std::ostream& os) const
16621662
} else {
16631663
// Determine how many leaf buffer passes are required for this grid
16641664
const io::StreamMetadata::Ptr meta = io::getStreamMetadataPtr(os);
1665-
assert(bool(meta));
1665+
OPENVDB_ASSERT(bool(meta));
16661666
uint16_t numPasses = 1;
16671667
meta->setCountingPasses(true);
16681668
meta->setPass(0);

openvdb/openvdb/Metadata.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "Types.h"
1010
#include "math/Math.h" // for math::isZero()
1111
#include "util/Name.h"
12+
#include "util/Assert.h"
1213
#include <cstdint>
1314
#include <iostream>
1415
#include <string>
@@ -279,9 +280,9 @@ TypedMetadata<T>::copy(const Metadata &other)
279280

280281
template<typename T>
281282
inline void
282-
TypedMetadata<T>::readValue(std::istream& is, Index32 /*numBytes*/)
283+
TypedMetadata<T>::readValue(std::istream& is, [[maybe_unused]] Index32 numBytes)
283284
{
284-
//assert(this->size() == numBytes);
285+
OPENVDB_ASSERT(this->size() == numBytes);
285286
is.read(reinterpret_cast<char*>(&mValue), this->size());
286287
}
287288

openvdb/openvdb/io/Compression.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "Compression.h"
55

66
#include <openvdb/Exceptions.h>
7+
#include <openvdb/util/Assert.h>
78
#include <openvdb/util/logging.h>
89
#ifdef OPENVDB_USE_ZLIB
910
#include <zlib.h>
@@ -101,7 +102,7 @@ zipToStream(std::ostream& os, const char* data, size_t numBytes)
101102
} else {
102103
// Write the size of the uncompressed data.
103104
// numBytes expected to be <= the max value + 1 of a signed int64
104-
assert(numBytes < size_t(std::numeric_limits<Int64>::max()));
105+
OPENVDB_ASSERT(numBytes < size_t(std::numeric_limits<Int64>::max()));
105106
Int64 negBytes = -Int64(numBytes);
106107
os.write(reinterpret_cast<char*>(&negBytes), 8);
107108
// Write the uncompressed data.
@@ -230,7 +231,7 @@ bloscToStream(std::ostream& os, const char* data, size_t valSize, size_t numVals
230231
{
231232
const size_t inBytes = valSize * numVals;
232233
// inBytes expected to be <= the max value + 1 of a signed int64
233-
assert(inBytes < size_t(std::numeric_limits<Int64>::max()));
234+
OPENVDB_ASSERT(inBytes < size_t(std::numeric_limits<Int64>::max()));
234235

235236
int outBytes = int(inBytes) + BLOSC_MAX_OVERHEAD;
236237
std::unique_ptr<char[]> compressedData(new char[outBytes]);

openvdb/openvdb/io/Compression.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <openvdb/Types.h>
88
#include <openvdb/MetaMap.h>
99
#include <openvdb/math/Math.h> // for negative()
10+
#include <openvdb/util/Assert.h>
1011
#include "io.h" // for getDataCompression(), etc.
1112
#include "DelayedLoadMetadata.h"
1213
#include <algorithm>
@@ -249,7 +250,7 @@ readData(std::istream& is, T* data, Index count, uint32_t compression,
249250
{
250251
const bool seek = data == nullptr;
251252
if (seek) {
252-
assert(!getStreamMetadataPtr(is) || getStreamMetadataPtr(is)->seekable());
253+
OPENVDB_ASSERT(!getStreamMetadataPtr(is) || getStreamMetadataPtr(is)->seekable());
253254
}
254255
const bool hasCompression = compression & (COMPRESS_BLOSC | COMPRESS_ZIP);
255256

@@ -471,7 +472,7 @@ readCompressedValues(std::istream& is, ValueT* destBuf, Index destCount,
471472
const bool maskCompressed = compression & COMPRESS_ACTIVE_MASK;
472473

473474
const bool seek = (destBuf == nullptr);
474-
assert(!seek || (!meta || meta->seekable()));
475+
OPENVDB_ASSERT(!seek || (!meta || meta->seekable()));
475476

476477
// Get delayed load metadata if it exists
477478

@@ -732,7 +733,7 @@ writeCompressedValues(std::ostream& os, ValueT* srcBuf, Index srcCount,
732733
} // else inactive value 0
733734
}
734735
}
735-
assert(tempCount == valueMask.countOn());
736+
OPENVDB_ASSERT(tempCount == valueMask.countOn());
736737

737738
// Write out the mask that selects between two inactive values.
738739
selectionMask.save(os);

openvdb/openvdb/io/DelayedLoadMetadata.cc

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "DelayedLoadMetadata.h"
55

66
#include <openvdb/points/StreamCompression.h>
7+
#include <openvdb/util/Assert.h>
78

89
#ifdef OPENVDB_USE_BLOSC
910
#include <blosc.h>
@@ -120,27 +121,27 @@ void DelayedLoadMetadata::resizeCompressedSize(size_t size)
120121

121122
DelayedLoadMetadata::MaskType DelayedLoadMetadata::getMask(size_t index) const
122123
{
123-
assert(DelayedLoadMetadata::isRegisteredType());
124-
assert(index < mMask.size());
124+
OPENVDB_ASSERT(DelayedLoadMetadata::isRegisteredType());
125+
OPENVDB_ASSERT(index < mMask.size());
125126
return mMask[index];
126127
}
127128

128129
void DelayedLoadMetadata::setMask(size_t index, const MaskType& value)
129130
{
130-
assert(index < mMask.size());
131+
OPENVDB_ASSERT(index < mMask.size());
131132
mMask[index] = value;
132133
}
133134

134135
DelayedLoadMetadata::CompressedSizeType DelayedLoadMetadata::getCompressedSize(size_t index) const
135136
{
136-
assert(DelayedLoadMetadata::isRegisteredType());
137-
assert(index < mCompressedSize.size());
137+
OPENVDB_ASSERT(DelayedLoadMetadata::isRegisteredType());
138+
OPENVDB_ASSERT(index < mCompressedSize.size());
138139
return mCompressedSize[index];
139140
}
140141

141142
void DelayedLoadMetadata::setCompressedSize(size_t index, const CompressedSizeType& value)
142143
{
143-
assert(index < mCompressedSize.size());
144+
OPENVDB_ASSERT(index < mCompressedSize.size());
144145
mCompressedSize[index] = value;
145146
}
146147

@@ -174,7 +175,7 @@ void DelayedLoadMetadata::readValue(std::istream& is, Index32 numBytes)
174175
mMask.resize(count);
175176

176177
// resize should never modify capacity for smaller vector sizes
177-
assert(mMask.capacity() >= paddedCount);
178+
OPENVDB_ASSERT(mMask.capacity() >= paddedCount);
178179

179180
compression::bloscDecompress(reinterpret_cast<char*>(mMask.data()), count*sizeof(MaskType), mMask.capacity()*sizeof(MaskType), compressedBuffer.get());
180181
#endif
@@ -202,7 +203,7 @@ void DelayedLoadMetadata::readValue(std::istream& is, Index32 numBytes)
202203
mCompressedSize.resize(count);
203204

204205
// resize should never modify capacity for smaller vector sizes
205-
assert(mCompressedSize.capacity() >= paddedCount);
206+
OPENVDB_ASSERT(mCompressedSize.capacity() >= paddedCount);
206207

207208
compression::bloscDecompress(reinterpret_cast<char*>(mCompressedSize.data()), count*sizeof(CompressedSizeType), mCompressedSize.capacity()*sizeof(CompressedSizeType), compressedBuffer.get());
208209
#endif
@@ -231,12 +232,12 @@ void DelayedLoadMetadata::readValue(std::istream& is, Index32 numBytes)
231232
void DelayedLoadMetadata::writeValue(std::ostream& os) const
232233
{
233234
// metadata has a limit of 2^32 bytes
234-
assert(mMask.size() < std::numeric_limits<Index32>::max());
235-
assert(mCompressedSize.size() < std::numeric_limits<Index32>::max());
235+
OPENVDB_ASSERT(mMask.size() < std::numeric_limits<Index32>::max());
236+
OPENVDB_ASSERT(mCompressedSize.size() < std::numeric_limits<Index32>::max());
236237

237238
if (mMask.empty() && mCompressedSize.empty()) return;
238239

239-
assert(mCompressedSize.empty() || (mMask.size() == mCompressedSize.size()));
240+
OPENVDB_ASSERT(mCompressedSize.empty() || (mMask.size() == mCompressedSize.size()));
240241

241242
Index32 count = static_cast<Index32>(mMask.size());
242243
os.write(reinterpret_cast<const char*>(&count), sizeof(Index32));
@@ -254,7 +255,7 @@ void DelayedLoadMetadata::writeValue(std::ostream& os) const
254255
}
255256

256257
if (compressedBuffer) {
257-
assert(compressedBytes < std::numeric_limits<Index32>::max());
258+
OPENVDB_ASSERT(compressedBytes < std::numeric_limits<Index32>::max());
258259
Index32 bytes(static_cast<Index32>(compressedBytes));
259260
os.write(reinterpret_cast<const char*>(&bytes), sizeof(Index32));
260261
os.write(reinterpret_cast<const char*>(compressedBuffer.get()), compressedBytes);
@@ -281,7 +282,7 @@ void DelayedLoadMetadata::writeValue(std::ostream& os) const
281282
}
282283

283284
if (compressedBuffer) {
284-
assert(compressedBytes < std::numeric_limits<Index32>::max());
285+
OPENVDB_ASSERT(compressedBytes < std::numeric_limits<Index32>::max());
285286
Index32 bytes(static_cast<Index32>(compressedBytes));
286287
os.write(reinterpret_cast<const char*>(&bytes), sizeof(Index32));
287288
os.write(reinterpret_cast<const char*>(compressedBuffer.get()), compressedBytes);

0 commit comments

Comments
 (0)