diff --git a/README.md b/README.md index a6f2c6667c..fac9b1e8e5 100644 --- a/README.md +++ b/README.md @@ -7188,6 +7188,14 @@ interpolation buffer, one can specify vertex buffers (`RTC_BUFFER_TYPE_VERTEX`) and vertex attribute buffers (`RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE`) as well. +The `bufferType` has to be either `RTC_BUFFER_TYPE_VERTEX` or +`RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE`, and the `bufferSlot` has to be a +valid slot of the specified buffer type, thus smaller than the number of +time steps for vertex buffers and smaller than the vertex attribute +count set using `rtcSetGeometryVertexAttributeCount` for vertex +attribute buffers. Otherwise an `RTC_ERROR_INVALID_ARGUMENT` error is +raised and no data is interpolated. + The `rtcInterpolate` call stores `valueCount` number of interpolated floating point values to the memory location pointed to by `P`. One can avoid storing the interpolated value by setting `P` to `NULL`. diff --git a/doc/src/api/rtcInterpolate.md b/doc/src/api/rtcInterpolate.md index 5b581f5c69..e2fee6ebd9 100644 --- a/doc/src/api/rtcInterpolate.md +++ b/doc/src/api/rtcInterpolate.md @@ -51,6 +51,14 @@ interpolation buffer, one can specify vertex buffers (`RTC_BUFFER_TYPE_VERTEX`) and vertex attribute buffers (`RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE`) as well. +The `bufferType` has to be either `RTC_BUFFER_TYPE_VERTEX` or +`RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE`, and the `bufferSlot` has to be a +valid slot of the specified buffer type, thus smaller than the number +of time steps for vertex buffers and smaller than the vertex attribute +count set using `rtcSetGeometryVertexAttributeCount` for vertex +attribute buffers. Otherwise an `RTC_ERROR_INVALID_ARGUMENT` error is +raised and no data is interpolated. + The `rtcInterpolate` call stores `valueCount` number of interpolated floating point values to the memory location pointed to by `P`. One can avoid storing the interpolated value by setting `P` to `NULL`. diff --git a/kernels/common/scene_curves.h b/kernels/common/scene_curves.h index 7350a20ecd..68abf10a9e 100644 --- a/kernels/common/scene_curves.h +++ b/kernels/common/scene_curves.h @@ -545,16 +545,20 @@ namespace embree unsigned int valueCount = args->valueCount; /* calculate base pointer and stride */ - assert((bufferType == RTC_BUFFER_TYPE_VERTEX && bufferSlot < numTimeSteps) || - (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE && bufferSlot <= vertexAttribs.size())); const char* src = nullptr; size_t stride = 0; if (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE) { + if (unlikely(bufferSlot >= vertexAttribs.size())) + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid vertex attribute buffer slot specified for interpolation"); src = vertexAttribs[bufferSlot].getPtr(); stride = vertexAttribs[bufferSlot].getStride(); - } else { + } else if (bufferType == RTC_BUFFER_TYPE_VERTEX) { + if (unlikely(bufferSlot >= numTimeSteps)) + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid vertex buffer slot specified for interpolation"); src = vertices[bufferSlot].getPtr(); stride = vertices[bufferSlot].getStride(); + } else { + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid buffer type specified for interpolation"); } for (unsigned int i=0; i= vertexAttribs.size())) + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid vertex attribute buffer slot specified for interpolation"); const char* vsrc = vertexAttribs[bufferSlot].getPtr(); const size_t vstride = vertexAttribs[bufferSlot].getStride(); @@ -730,9 +735,10 @@ namespace embree } /* interpolation for vertex buffers */ - else + else if (bufferType == RTC_BUFFER_TYPE_VERTEX) { - assert(bufferSlot < numTimeSteps); + if (unlikely(bufferSlot >= numTimeSteps)) + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid vertex buffer slot specified for interpolation"); const char* vsrc = vertices[bufferSlot].getPtr(); const char* tsrc = tangents[bufferSlot].getPtr(); const size_t vstride = vertices[bufferSlot].getStride(); @@ -754,6 +760,8 @@ namespace embree if (ddPdudu) mem>::storeu(valid,ddPdudu+i,curve.eval_dudu(u)); } } + else + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid buffer type specified for interpolation"); } void interpolate(const RTCInterpolateArguments* const args) { diff --git a/kernels/common/scene_grid_mesh.h b/kernels/common/scene_grid_mesh.h index cd374912f5..76f50522bb 100644 --- a/kernels/common/scene_grid_mesh.h +++ b/kernels/common/scene_grid_mesh.h @@ -86,16 +86,20 @@ namespace embree unsigned int valueCount = args->valueCount; /* calculate base pointer and stride */ - assert((bufferType == RTC_BUFFER_TYPE_VERTEX && bufferSlot < numTimeSteps) || - (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE && bufferSlot <= vertexAttribs.size())); const char* src = nullptr; size_t stride = 0; if (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE) { + if (unlikely(bufferSlot >= vertexAttribs.size())) + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid vertex attribute buffer slot specified for interpolation"); src = vertexAttribs[bufferSlot].getPtr(); stride = vertexAttribs[bufferSlot].getStride(); - } else { + } else if (bufferType == RTC_BUFFER_TYPE_VERTEX) { + if (unlikely(bufferSlot >= numTimeSteps)) + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid vertex buffer slot specified for interpolation"); src = vertices[bufferSlot].getPtr(); stride = vertices[bufferSlot].getStride(); + } else { + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid buffer type specified for interpolation"); } const Grid& grid = grids[primID]; diff --git a/kernels/common/scene_line_segments.h b/kernels/common/scene_line_segments.h index a672abd8d2..f896628077 100644 --- a/kernels/common/scene_line_segments.h +++ b/kernels/common/scene_line_segments.h @@ -49,16 +49,20 @@ namespace embree unsigned int valueCount = args->valueCount; /* calculate base pointer and stride */ - assert((bufferType == RTC_BUFFER_TYPE_VERTEX && bufferSlot < numTimeSteps) || - (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE && bufferSlot <= vertexAttribs.size())); const char* src = nullptr; size_t stride = 0; if (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE) { + if (unlikely(bufferSlot >= vertexAttribs.size())) + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid vertex attribute buffer slot specified for interpolation"); src = vertexAttribs[bufferSlot].getPtr(); stride = vertexAttribs[bufferSlot].getStride(); - } else { + } else if (bufferType == RTC_BUFFER_TYPE_VERTEX) { + if (unlikely(bufferSlot >= numTimeSteps)) + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid vertex buffer slot specified for interpolation"); src = vertices[bufferSlot].getPtr(); stride = vertices[bufferSlot].getStride(); + } else { + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid buffer type specified for interpolation"); } for (unsigned int i=0; ivalueCount; /* calculate base pointer and stride */ - assert((bufferType == RTC_BUFFER_TYPE_VERTEX && bufferSlot < numTimeSteps) || - (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE && bufferSlot <= vertexAttribs.size())); const char* src = nullptr; size_t stride = 0; if (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE) { + if (unlikely(bufferSlot >= vertexAttribs.size())) + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid vertex attribute buffer slot specified for interpolation"); src = vertexAttribs[bufferSlot].getPtr(); stride = vertexAttribs[bufferSlot].getStride(); - } else { + } else if (bufferType == RTC_BUFFER_TYPE_VERTEX) { + if (unlikely(bufferSlot >= numTimeSteps)) + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid vertex buffer slot specified for interpolation"); src = vertices[bufferSlot].getPtr(); stride = vertices[bufferSlot].getStride(); + } else { + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid buffer type specified for interpolation"); } for (unsigned int i=0; ivalueCount; /* calculate base pointer and stride */ - assert((bufferType == RTC_BUFFER_TYPE_VERTEX && bufferSlot < RTC_MAX_TIME_STEP_COUNT) || - (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE && bufferSlot < RTC_MAX_USER_VERTEX_BUFFERS)); const char* src = nullptr; size_t stride = 0; std::vector* baseEntry = nullptr; Topology* topo = nullptr; if (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE) { - assert(bufferSlot < vertexAttribs.size()); + if (unlikely(bufferSlot >= vertexAttribs.size())) + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid vertex attribute buffer slot specified for interpolation"); src = vertexAttribs[bufferSlot].getPtr(); stride = vertexAttribs[bufferSlot].getStride(); baseEntry = &vertex_attrib_buffer_tags[bufferSlot]; int topologyID = vertexAttribs[bufferSlot].userData; topo = &topology[topologyID]; - } else { - assert(bufferSlot < numTimeSteps); + } else if (bufferType == RTC_BUFFER_TYPE_VERTEX) { + if (unlikely(bufferSlot >= numTimeSteps)) + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid vertex buffer slot specified for interpolation"); src = vertices[bufferSlot].getPtr(); stride = vertices[bufferSlot].getStride(); baseEntry = &vertex_buffer_tags[bufferSlot]; topo = &topology[0]; + } else { + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid buffer type specified for interpolation"); } bool has_P = P; @@ -936,25 +938,27 @@ namespace embree unsigned int valueCount = args->valueCount; /* calculate base pointer and stride */ - assert((bufferType == RTC_BUFFER_TYPE_VERTEX && bufferSlot < RTC_MAX_TIME_STEP_COUNT) || - (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE && bufferSlot < RTC_MAX_USER_VERTEX_BUFFERS)); const char* src = nullptr; size_t stride = 0; std::vector* baseEntry = nullptr; Topology* topo = nullptr; if (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE) { - assert(bufferSlot < vertexAttribs.size()); + if (unlikely(bufferSlot >= vertexAttribs.size())) + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid vertex attribute buffer slot specified for interpolation"); src = vertexAttribs[bufferSlot].getPtr(); stride = vertexAttribs[bufferSlot].getStride(); baseEntry = &vertex_attrib_buffer_tags[bufferSlot]; int topologyID = vertexAttribs[bufferSlot].userData; topo = &topology[topologyID]; - } else { - assert(bufferSlot < numTimeSteps); + } else if (bufferType == RTC_BUFFER_TYPE_VERTEX) { + if (unlikely(bufferSlot >= numTimeSteps)) + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid vertex buffer slot specified for interpolation"); src = vertices[bufferSlot].getPtr(); stride = vertices[bufferSlot].getStride(); baseEntry = &vertex_buffer_tags[bufferSlot]; topo = &topology[0]; + } else { + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid buffer type specified for interpolation"); } const int* valid = (const int*) valid_i; diff --git a/kernels/common/scene_triangle_mesh.h b/kernels/common/scene_triangle_mesh.h index 3f014d85a2..533a41921c 100644 --- a/kernels/common/scene_triangle_mesh.h +++ b/kernels/common/scene_triangle_mesh.h @@ -62,16 +62,20 @@ namespace embree unsigned int valueCount = args->valueCount; /* calculate base pointer and stride */ - assert((bufferType == RTC_BUFFER_TYPE_VERTEX && bufferSlot < numTimeSteps) || - (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE && bufferSlot <= vertexAttribs.size())); const char* src = nullptr; size_t stride = 0; if (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE) { + if (unlikely(bufferSlot >= vertexAttribs.size())) + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid vertex attribute buffer slot specified for interpolation"); src = vertexAttribs[bufferSlot].getPtr(); stride = vertexAttribs[bufferSlot].getStride(); - } else { + } else if (bufferType == RTC_BUFFER_TYPE_VERTEX) { + if (unlikely(bufferSlot >= numTimeSteps)) + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid vertex buffer slot specified for interpolation"); src = vertices[bufferSlot].getPtr(); stride = vertices[bufferSlot].getStride(); + } else { + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid buffer type specified for interpolation"); } for (unsigned int i=0; i