diff --git a/tsd/src/tsd/core/Object.cpp b/tsd/src/tsd/core/Object.cpp index b4bcff61..cbd1d658 100644 --- a/tsd/src/tsd/core/Object.cpp +++ b/tsd/src/tsd/core/Object.cpp @@ -158,6 +158,9 @@ void Object::updateANARIParameter(anari::Device d, const char *n, AnariObjectCache *cache) const { + if (!o) + return; + if (cache && !p.isEnabled()) { anari::unsetParameter(d, o, n); } else if (cache && p.value().holdsObject()) { @@ -188,6 +191,9 @@ void Object::updateANARIParameter(anari::Device d, void Object::updateAllANARIParameters( anari::Device d, anari::Object o, AnariObjectCache *cache) const { + if (!o) + return; + for (size_t i = 0; i < numParameters(); i++) updateANARIParameter(d, o, parameterAt(i), parameterNameAt(i), cache); } diff --git a/tsd/src/tsd/objects/Array.cpp b/tsd/src/tsd/objects/Array.cpp index 48264ad9..fc0d6af2 100644 --- a/tsd/src/tsd/objects/Array.cpp +++ b/tsd/src/tsd/objects/Array.cpp @@ -6,6 +6,7 @@ #endif #include "tsd/objects/Array.hpp" +#include "tsd/core/Logging.hpp" // std #include #if TSD_USE_CUDA @@ -182,6 +183,13 @@ Array::Array(anari::DataType arrayType, else if (anari::isObject(type)) return; + if (isEmpty()) { + logWarning("%s of %s elements created with 0 size", + anari::toString(this->type()), + anari::toString(this->elementType())); + return; + } + if (kind == MemoryKind::CUDA) { #if TSD_USE_CUDA cudaMalloc(&m_data, size() * elementSize()); diff --git a/tsd/src/tsd/rendering/RenderIndex.cpp b/tsd/src/tsd/rendering/RenderIndex.cpp index c6af8767..b63768d3 100644 --- a/tsd/src/tsd/rendering/RenderIndex.cpp +++ b/tsd/src/tsd/rendering/RenderIndex.cpp @@ -79,13 +79,14 @@ void RenderIndex::populate(Context &ctx, bool setAsUpdateDelegate) foreach_item_const(objArray, [&](auto *obj) { if (!obj) return; - auto o = handleArray[obj->index()]; - obj->updateAllANARIParameters(d, o, &m_cache); - if (obj->type() == ANARI_SURFACE) - anari::setParameter(d, o, "id", uint32_t(obj->index())); - else if (obj->type() == ANARI_VOLUME) - anari::setParameter(d, o, "id", uint32_t(obj->index()) | 0x80000000u); - anari::commitParameters(d, o); + if (auto o = handleArray[obj->index()]; o != nullptr) { + obj->updateAllANARIParameters(d, o, &m_cache); + if (obj->type() == ANARI_SURFACE) + anari::setParameter(d, o, "id", uint32_t(obj->index())); + else if (obj->type() == ANARI_VOLUME) + anari::setParameter(d, o, "id", uint32_t(obj->index()) | 0x80000000u); + anari::commitParameters(d, o); + } }); }; @@ -125,7 +126,8 @@ void RenderIndex::signalObjectAdded(const Object *obj) switch (obj->type()) { case ANARI_SURFACE: { auto s = m_cache.surface.insert((anari::Surface)o); - anari::setParameter(d, o, "id", uint32_t(obj->index())); + if (o) + anari::setParameter(d, o, "id", uint32_t(obj->index())); } break; case ANARI_GEOMETRY: m_cache.geometry.insert((anari::Geometry)o); @@ -155,7 +157,8 @@ void RenderIndex::signalObjectAdded(const Object *obj) break; // no-op } - anari::commitParameters(d, o); + if (o) + anari::commitParameters(d, o); } void RenderIndex::signalParameterUpdated(const Object *o, const Parameter *p) @@ -221,7 +224,7 @@ void RenderIndex::signalRemoveAllObjects() void RenderIndex::updateObjectArrayData(const Array *a) const { auto elementType = a->elementType(); - if (!a || !anari::isObject(elementType)) + if (!a || !anari::isObject(elementType) || a->isEmpty()) return; if (auto arr = (anari::Array)m_cache.getHandle(a); arr != nullptr) {